如何更改\ SooClient的SOAPAction HTTP标头? [英] How to change SOAPAction HTTP header for \SoapClient?

查看:147
本文介绍了如何更改\ SooClient的SOAPAction HTTP标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当挑剔的SoapApi,我想与之交谈。

I have a rather nitpicky SoapApi that I want to talk to.

我需要更改 SoapAction 与HTTP请求一起发送的标头。

I need to change the SoapAction header that is sent with the HTTP request.

我不是在谈论与此一起传递的 \SoapHeader Soap Envelop作为XML消息的一部分,但是HTTP标头 SOAPAction

I am not talking about \SoapHeader that is passed along with the Soap Envelop as part of the XML message, but the HTTP header SOAPAction.

使用curl我会发送请求如下:

Using curl I would send the request like this:

curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction: http://tempuri.org/my-custom-action" --data @message.xml http://some-soap-endpoint.asmx --proxy le-proxy:3218

似乎只能在 SoapClient 创建期间设置SoapAction

It seems one can only set the SoapAction during SoapClient creation

推荐答案

我停止使用 \SoapClient 以及此特定的SoapAPI(< a href =https://stackoverflow.com/questions/33521051/how-to-disable-auto-escaping-of-html-entities-in-php-soapclient> fo不同的原因也使用Guzzle而不是简单地模仿卷曲请求。

I stopped using \SoapClient and for this particular "Soap" API (for a different reason as well) used Guzzle instead simply mimicking the curl request.

在那里,我用API对原始XML发出了一个简单的post请求,并且现在它正在运作;即使我认为这是不能使用专用的 \SoapService 的缺点。

There, I fired a simple post request with raw XML against the API, and now it is working; even though I think it's a downside of not being able to use the dedicated \SoapService.

如果有人想知道如何通过guzzle发送XML请求,可以这样做:

If one wonders how to send a XML requests via guzzle, one can do:

$options = [
    'body'    => $body,
    'headers' => [
        "Content-Type" => "text/xml; charset=utf-8",
        'SOAPAction'   => 'tempuri.org/my-custom-action',

    ],
    'proxy'   => 'tcp://le-proxy:3128',
];
$client = new Client();
$soapRequest = $client->createRequest(
    'post',
    "http://some-soap-endpoint.asmx",
    $options
);

try {
    $response = $client->send($soapRequest);
} catch (RequestException $e) {
    /**
     * error handling
     */
}

我认为这是一种解决方法。

I consider this a workaround though.

这篇关于如何更改\ SooClient的SOAPAction HTTP标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆