問題描述
我正在編寫一個基于 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!