我正在尝试使用 PHP SoapClient 来执行对第三方应用程序的请求。当我创建 SoapClient 对象时,我收到有关 WSDL 数据过早结束的错误。在尝试诊断错误时,我发现 WSDL URI 的 file_get_contents() 没有返回整个 XML。事实上,它经常返回不同数量的 WSDL。这是我的测试程序:$xml = file_get_contents('https://webservices3.autotask.net/atservices/1.6/atws.wsdl');echo $xml . "\n";echo strlen($xml). "\n";我每次得到大约 57k 字节(195628 是正确的值),有时更多而且很少我得到整个 XML。我认为这是一个 PHP 问题,因为为该 URI 每次调用 curl 或 wget 100 次的 shell 循环将在 100% 的时间内返回整个文件。我使用的是 PHP 5.4.16,我知道它很旧(2013 年),但是这个过程工作了大约一个月,然后就完全停止了。我试过更改超时、HTTP 协议版本、PHP 内存设置,但我不明白为什么 file_get_contents 会这样。任何建议表示赞赏。卷曲测试:for a in $( seq 1 100 ); do curl -o wsdl.$a https://webservices3.autotask.net/atservices/1.6/atws.wsdl; done测试:for a in $( seq 1 100 ); do wget -O wsdl.$a https://webservices3.autotask.net/atservices/1.6/atws.wsdl; done更新 1:将 maxlen 设置为一些愚蠢的大数不会影响行为:$xml = file_get_contents('https://webservices3.autotask.net/atservices/1.6/atws.wsdl', false, null, 0, 999999);echo $xml . "\n";echo strlen($xml). "\n";更新 2:$ curl -s -D /dev/stderr -- https://webservices3.autotask.net/atservices/1.6/atws.wsdl > /dev/nullHTTP/1.1 200 OKContent-Type: text/xmlLast-Modified: Wed, 29 Apr 2020 14:38:25 GMTAccept-Ranges: bytesETag: "39163cd7331ed61:0"Server: Microsoft-IIS/8.5X-Powered-By: ASP.NETContent-Security-Policy: default-src 'self' https: *;script-src 'self' 'unsafe-inline' 'unsafe-eval' https: *;style-src 'self' 'unsafe-inline';img-src 'self' https://walkme.psa.datto.com/Images/ data: https://www.datto.com/img/Date: Fri, 08 May 2020 15:22:28 GMTContent-Length: 195628
2 回答

胡说叔叔
TA贡献1804条经验 获得超8个赞
webservices3.autotask.net 的响应标头错误
HTTP/1.1 200 OK
Content-Type: text/xml
Accept-Ranges: bytes
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
Cteonnt-Length: 195628
Cache-Control: private
Content-Encoding: gzip
Transfer-Encoding: chunked
注意:Cteonnt-Length: 195628应该是Content-Length: 195628
那为什么file_get_contents不能正确处理请求。
所以,修复响应或设置maxlen
- 2 回答
- 0 关注
- 282 浏览
添加回答
举报
0/150
提交
取消