remiheens
remiheens

Reputation: 367

Adding custom HTTP header in call soap using PHP

I'm trying to connect to a WebService SOAP. The service requires us to add a custom parameter in the HTTP header of the soap call

$context = array('http' =>
    array(
        'header'  => "APIToken: $api_token\r\n"
    )
);
$soap_options = array(
    'stream_context' => stream_context_create($context),
    'encoding' => 'UTF-8',
    'exceptions' => TRUE,
    'trace' => true,
    'local_cert' => 'mycert.pem',
    'passphrase'=>'xxx',
    'location'=>$this->url_soap_dev
);

$soap_client = new SoapClient('soap.wsdl', $soap_options);

$args = array(
    'param1' => $var,
    'param2' => 0,
    'optionalParameters'=>array()
);

$ret = $soap_client->RemoteFunction(array('parameter'=>$args));  

And this is my Request Headers:

POST /server/soap HTTP/1.1
Host: domain.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.2.6-1+lenny16
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Content-Length: 400

Where can I add custom param ?

Thx.

Upvotes: 2

Views: 4829

Answers (2)

Trevor
Trevor

Reputation: 63

With php 5.6, I got the sample code at the top working without any functional changes all I did was to change WSDL, header values to the server I'm using.

Upvotes: 0

remiheens
remiheens

Reputation: 367

This process works fine with PHP >= 5.3

Here is the patch to add this functionality https://bugs.php.net/bug.php?id=49853

Upvotes: 2

Related Questions