我正在编写一个基于 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
在 SOAP 库中.但没有这样的运气.
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.
<子>(我在这里发现了这个悬而未决的问题 http://www.phpfreaks.com/forums/index.php?topic=125387.0,我复制了 b/c 我有同样的问题)
(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)
尝试为 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 Header的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!