gpt4 book ai didi

PHP SoapClient() : send "User-Agent" and "Accept" HTTP Header

转载 作者:IT王子 更新时间:2023-10-29 00:12:39 25 4
gpt4 key购买 nike

由于防火墙审核,请求必须始终具有“UserAgent”和“Accept” header 。

我试过这个:

$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')
)
)
)
);

服务器soap收到的请求

GET /soap.php?wsdl HTTP/1.1
Host: www.soap.com
User-Agent: PHP/SOAP
Connection: close

预期结果

GET /soap.php?wsdl HTTP/1.1
Host: www.soap.com
Accept application/xml
User-Agent: PHP/SOAP
Connection: close

为什么没有发送“接受”? “用户代理”有效!

最佳答案

SoapClient 构造函数在生成请求 header 时不会读取所有的 stream_context 选项。但是,您可以将任意 header 放在 http 内的 header 选项中的单个字符串中:

$soapclient = new SoapClient($wsdl, [
'stream_context' => stream_context_create([
'user_agent' => 'PHP/SOAP',
'http'=> [
'header' => "Accept: application/xml\r\n
X-WHATEVER: something"
]
])
]);

如果设置多个,用\r\n分隔。

(如 Ian Phillips 所述,“user_agent”可以放在 stream_context 的根部,也可以放在“http”部分。)

关于PHP SoapClient() : send "User-Agent" and "Accept" HTTP Header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23358714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com