SoapClient “无法连接到主机”异常,带有一个 WSDL API


SoapClient "Could not connect to host" exception with one WSDL API

在迁移到新的 OVH VPS 机器后,我与 API 的一个 WSDL 连接出现问题,所以这可能是某种奇怪的配置错误。

我与 SoapClient 一起使用的其他 WSDL 工作正常,没有问题。我可以在地址上使用file_get_contents,但是当我使用SoapClient时,当我尝试使用该 API 的过程时,我会给出异常"无法连接到主机"。

有什么想法吗?我已经尝试了一些带有一些SSL选项的stream_context。最有趣的是,在其他OVH VPS上工作正常。

系统是 Debian 8,搭载 PHP 5.6.19。

WSDL的地址在这里: https://api-test.paczkawruchu.pl/WebServicePwR/WebServicePwRTest.asmx?WSDL

在咨询了WSDL提供者并检查了双方的日志后,我们找到了anwser。看起来 PHP 5.6 有一些问题,您必须将参数更改为 SOAP 1.2。这最终解决了这个问题。解决方案可以在这里找到,在第一条评论中:SOAP PHP 错误解析 WSDL:无法加载外部实体?

// options for ssl in php 5.6.5
$opts = array(
    'ssl' => array('ciphers'=>'RC4-SHA', 'verify_peer'=>false, 'verify_peer_name'=>false)
);
// SOAP 1.2 client
$params = array ('encoding' => 'UTF-8', 'verifypeer' => false, 'verifyhost' => false, 'soap_version' => SOAP_1_2, 'trace' => 1, 'exceptions' => 1, "connection_timeout" => 180, 'stream_context' => stream_context_create($opts) );
$oSoapClient = new SoapClient ( $url . "?WSDL", $params );
相关文章: