dsimib1625 2016-06-08 06:44
浏览 132

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

I had no problem running the following code in my controller.

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());
        });

Following is my request HTTP header.

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

But let say I want to add randomName: some_session_id into the HTTP header, what/how should I do it? Have try -header() and customHeader() but this only add into the xml envelope header which is not I want.

  • 写回答

1条回答 默认 最新

  • douyi8315 2016-06-08 06:55
    关注

    For adding data into http header you need to do it like it's on documentation

    $data = [
                'CurrencyFrom' => 'USD',
                'CurrencyTo'   => 'EUR',
                'RateDate'     => '2014-06-05',
                'Amount'       => '1000'
            ];
    
            // Using the added service
            SoapWrapper::service('currency', function ($service) use ($data) {
                var_dump($service->getFunctions());
                var_dump($service->call('GetConversionAmount', [$data])->GetConversionAmountResult);
            });
    

    In your case you don't send any additional data in your service call so you should do it like it's below

    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());
            });
    

    EDIT:

    For adding custom header, you should use

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

    from SoapWrapper/Service.

    So in your case you should do something like

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

    Hope it helps

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据