2012-10-03 158 views
2

我试图连接到WebService SOAP。 服务要求我们在SOAP调用使用PHP在调用soap中添加自定义HTTP标头

$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)); 

的HTTP标头添加自定义的参数,这是我的请求报头:

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 

我在哪里可以添加自定义PARAM?

Thx。

回答

0

用PHP 5.6的补丁,我在上面工作的示例代码没有任何功能上的改变都是我确实是将WSDL,标头值更改为我正在使用的服务器。