修改 PHP / SOAP 代码以在所有请求中添加 HTTP 标头
我继承了一些 php SOAP 代码,由于我们正在使用的服务发生了变化,我需要修改为“在所有请求的 HTTP 标头中添加授权”。我不知道该怎么做,甚至不知道是否可能。
部分相关代码如下所示:
function soap_connect() {
$soap_options = array(
'soap_version' => SOAP_1_2,
'encoding' => 'UTF-8',
'exceptions' => FALSE
);
try {
$this->soap_client = new SoapClient($this->configuration['wsdl'], $soap_options);
} catch (SoapFault $fault) {
return FALSE;
}
return TRUE;
}
我认为,据我了解,它应该只是输出以下内容(现在):
Content-Type: application/soap+xml;charset=UTF-8;action="http://ws.testserver.net/nsp/client/hsserve/listHardware"
Content-Length: 255
...
文档说最终的 HTTP 请求应该如下所示:
Content-Type: application/soap+xml;charset=UTF-8;action="http://ws.testserver.net/nsp/client/hsserve/listHardware"
Authorization: WRAP access_token=Z-H7SnqL49eQ2Qp5pLH8k-RVxHfewgIIDt4VCeI2CNnrS4-gBMzPWbfZuMhgvISVV-uTSikS1SqO0n2PRkH3ysQ-uWbvU9podPAm6HiiIS5W2mtpXUfN9ErBmkjF6hDw
Content-Length: 255
I;ve inherited some php SOAP code and due to changes in the service we are using, I need to modify to "add an authorization in the HTTP headers of all requests". I'm not sure what to do and if its even possible.
Part of the relevant code looks like this:
function soap_connect() {
$soap_options = array(
'soap_version' => SOAP_1_2,
'encoding' => 'UTF-8',
'exceptions' => FALSE
);
try {
$this->soap_client = new SoapClient($this->configuration['wsdl'], $soap_options);
} catch (SoapFault $fault) {
return FALSE;
}
return TRUE;
}
I think, as I understand it, it should be just outputting the following (right now):
Content-Type: application/soap+xml;charset=UTF-8;action="http://ws.testserver.net/nsp/client/hsserve/listHardware"
Content-Length: 255
...
The documentatino says that the final HTTP request should look like:
Content-Type: application/soap+xml;charset=UTF-8;action="http://ws.testserver.net/nsp/client/hsserve/listHardware"
Authorization: WRAP access_token=Z-H7SnqL49eQ2Qp5pLH8k-RVxHfewgIIDt4VCeI2CNnrS4-gBMzPWbfZuMhgvISVV-uTSikS1SqO0n2PRkH3ysQ-uWbvU9podPAm6HiiIS5W2mtpXUfN9ErBmkjF6hDw
Content-Length: 255
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加流上下文以向 HTTP 调用提供附加标头。
请参阅
SoapClient::__construct()
和 HTTP 上下文选项 了解更多信息,Add a stream context to provide the additional headers to the HTTP call.
Please see
SoapClient::__construct()
and HTTP context options for further information,在没有看到 wsdl 的情况下,很难弄清楚服务器期望什么类型的结构,但这里有一些示例:
简单 HTTP 身份验证
对于实现更高级的自定义方法的服务器:
It's quite difficult to figure out what type of structure the server is expecting without seeing the wsdl, but here are a few examples:
Simple HTTP auth
For the servers which implement a more advanced, custom method: