我遇到了一種情況,我不得不提供一個哈希值,用於驗證目的的請求的HTTP頭中的soap請求的所有文本。
class AuthenticatingSoapClient extends SoapClient {
private $secretKey = "secretKeyString";
private $context;
function __construct($wsdl, $options) {
// Create the stream_context and add it to the options
$this->context = stream_context_create();
$options = array_merge($options, array('stream_context' => $this->context));
parent::SoapClient($wsdl, $options);
}
// Override doRequest to calculate the authentication hash from the $request.
function __doRequest($request, $location, $action, $version, $one_way = 0) {
// Grab all the text from the request.
$xml = simplexml_load_string($request);
$innerText = dom_import_simplexml($xml)->textContent;
// Calculate the authentication hash.
$encodedText = utf8_encode($innerText);
$authHash = base64_encode(hash_hmac("sha256", $encodedText, $this->secretKey, true));
// Set the HTTP headers.
stream_context_set_option($this->context, array('http' => array('header' => 'AuthHash: '. $authHash)));
return (parent::__doRequest($request, $location, $action, $version, $one_way));
}
}
也許有人搜索會發現這個有用:我通過繼承SoapClient並使用stream_context選項設置頁眉做到了這一點。
這對的SOAPHeaders但我需要/尋找一種方式來修改由SoapClient的產生的請求的HTTP頭。 – user308891 2011-05-30 18:10:02
呵呵,HTTP頭文件!對不起,關於:) nuSOAP支持cookies,但你必須修改它來添加標題。 – igorw 2011-05-30 18:36:38