如何在SoapWrapper Laravel中将元素添加到HTTP头中?

时间:2016-06-08 06:44:27

标签: php laravel soap

我在控制器中运行以下代码没有问题。

SoapWrapper::add(function ($service) {
               $service
               ->name('Testing')
               ->wsdl('http://example.asmx?WSDL')
               ->trace(true);
             });

        // Using the added service
        SoapWrapper::service('Testing', function ($service) use ($data) {
            print_r($service->call('Function1', []));
            //print_r($service->getLastRequestHeaders());
        });

以下是我的请求HTTP标头。

POST http://example.asmx HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://tempuri.org/Function1"
Content-Length: 214
Host: some_host
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
randomName:some_session_id  //<------------which i want to add

但是,我想将randomName: some_session_id添加到HTTP标头中,我该怎么做/应该怎么做?请尝试-header()customHeader(),但这只会添加到我想要的xml信封标题中。

1 个答案:

答案 0 :(得分:1)

要将数据添加到http标头,您需要像documentation

那样进行操作
SoapWrapper::add(function ($service) {
               $service
               ->name('Testing')
               ->wsdl('http://example.asmx?WSDL')
               ->trace(true);
             });

        // Using the added service
        $data = session()->get('some_id');
        SoapWrapper::service('Testing', function ($service) use ($data) {
            print_r($service->call('Function1', [$data]));
            //print_r($service->getLastRequestHeaders());
        });

在您的情况下,您不会在服务电话中发送任何其他数据,因此您应该按照以下方式执行此操作

public function customHeader($header)
{
    $this->headers[] = $header;
    return $this;
}

修改

要添加自定义标题,您应该使用

SoapWrapper/Service

来自SoapWrapper::add(function ($service) { $service ->name('Testing') ->wsdl('http://example.asmx?WSDL') ->customHeader($customHeader) ->trace(true); });

所以在你的情况下你应该做类似

的事情
SELECT * FROM Test
WHERE
IF Condition = True
    Column1 = 'This'
    Column2 = 'That'
ELSE
    Column3 = 'This'
    column4 = 'That'

希望有所帮助