我遇到了一种情况,我不得不提供一个哈希值,用于验证目的的请求的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