ar0*_*968 13 php soap http-headers
由于防火墙审核,请求必须始终具有"UserAgent"和"Accept"标头.
我试过这个:
$soapclient = new soapclient('http://www.soap.com/soap.php?wsdl',
array('stream_context' => stream_context_create(
array(
'http'=> array(
'user_agent' => 'PHP/SOAP',
'accept' => 'application/xml')
)
)
)
);
Run Code Online (Sandbox Code Playgroud)
服务器soap收到的请求
GET /soap.php?wsdl HTTP/1.1
Host: www.soap.com
User-Agent: PHP/SOAP
Connection: close
Run Code Online (Sandbox Code Playgroud)
预期的结果
GET /soap.php?wsdl HTTP/1.1
Host: www.soap.com
Accept application/xml
User-Agent: PHP/SOAP
Connection: close
Run Code Online (Sandbox Code Playgroud)
为什么没有发送"接受"?"用户代理"有效!
ale*_*ino 16
生成请求标头时,SoapClient构造函数不会读取所有stream_context选项.但是,您可以在header选项内的单个字符串中放置任意标头http:
$soapclient = new SoapClient($wsdl, [
'stream_context' => stream_context_create([
'user_agent' => 'PHP/SOAP',
'http'=> [
'header' => "Accept: application/xml\r\n
X-WHATEVER: something"
]
])
]);
Run Code Online (Sandbox Code Playgroud)
要设置多个,请将它们分开\r\n.
(正如Ian Phillips所提到的,"user_agent"可以放在stream_context的根目录下,也可以放在"http"部分内.)