Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SoapClient set custom HTTP Header

I am doing some work writing a PHP-based SOAP client application that uses the SOAP libraries native to PHP5. I need to send a an HTTP cookie and an additional HTTP header as part of the request. The cookie part is no problem:

Code:

$client = new SoapClient($webServiceURI, array("exceptions" => 0, "trace" => 1, "encoding" => $phpInternalEncoding));
$client->__setCookie($kkey, $vvalue);

My problem is the HTTP header. I was hoping there would have been a function named

__setHeader

or

__setHttpHeader

in the SOAP libraries. But no such luck.

Anyone else dealt with this? Is there a workaround? Would a different SOAP library be easier to work with? Thanks.

(I found this unanswerd question here http://www.phpfreaks.com/forums/index.php?topic=125387.0, I copied it b/c i've the same issue)

like image 787
user308891 Avatar asked May 30 '11 17:05

user308891


People also ask

How do you add a header to a SOAP request in spring boot?

While using WebServiceTemplate, Spring provides numerous ways to intercept the request and modify the request and response. Hence, the interceptor can be a one way to add a header in the request. Similarly, we can implement WebServiceMessageCallback and override doWithMessage() method to add custom header.


1 Answers

Try setting a stream context for the soap client:

$client = new SoapClient($webServiceURI, array(
    "exceptions" => 0, 
    "trace" => 1, 
    "encoding" => $phpInternalEncoding,
    'stream_context' => stream_context_create(array(
        'http' => array(
            'header' => 'SomeCustomHeader: value'
        ),
    )),
));
like image 132
bedeabza Avatar answered Oct 17 '22 09:10

bedeabza