问题描述
我正在做一些工作,编写一个基于PHP的SOAP客户端应用程序,该应用程序使用PHP5固有的SOAP库.我需要发送一个HTTP cookie和一个额外的HTTP标头作为请求的一部分. Cookie部分没有问题:
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:
代码:
$client = new SoapClient($webServiceURI, array("exceptions" => 0, "trace" => 1, "encoding" => $phpInternalEncoding));
$client->__setCookie($kkey, $vvalue);
我的问题是HTTP标头.我希望会有一个名为
My problem is the HTTP header. I was hoping there would have been a function named
__ setHeader
或
__ setHttpHeader
.但是没有这种运气.
in the SOAP libraries. But no such luck.
还有其他人处理吗?有解决方法吗?使用其他SOAP库会更容易吗?谢谢.
Anyone else dealt with this? Is there a workaround? Would a different SOAP library be easier to work with? Thanks.
推荐答案
尝试为soap客户端设置流上下文:
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'
),
)),
));
这篇关于SoapClient设置自定义HTTP标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!