PHP Soap错误:无法连接到主机
有很多问题是类似这样的。但我尝试时没有找到解决方案。请在下面找到我的代码: Soap XML:PHP Soap错误:无法连接到主机,php,soap,soap-client,Php,Soap,Soap Client,有很多问题是类似这样的。但我尝试时没有找到解决方案。请在下面找到我的代码: Soap XML: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pos="http://PostWebService.org/"> <soap:Header> <pos:Authentication> <!--Optional:-->
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pos="http://PostWebService.org/">
<soap:Header>
<pos:Authentication>
<!--Optional:-->
<pos:UserName>xxxxxxx</pos:UserName>
<!--Optional:-->
<pos:Password>yyyyyyyy</pos:Password>
</pos:Authentication>
</soap:Header>
<soap:Body>
.....
</soap:Body>
</soap:Envelope>
请注意,我的Soap URL是https格式的。我从堆栈溢出中尝试了许多其他解决方案,但都不起作用。我想让任何人告诉我为什么我会犯这样的错误,以及我在请求中做错了什么
尝试了另一个代码,但仍然相同:
$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, 'keep_alive' => false,'trace' => 1, 'exceptions' => 1, "connection_timeout" => 180, 'stream_context' => stream_context_create($opts) );
$client = new SoapClient({soapurl},$params);
//Remaining as the same above
当我尝试使用SoapUI时,它给了我一个响应 最后,我得到了解决方案 我发现了问题。我试图连接的主机正在重定向到另一个域名。由于某些原因,PHP5.6不会自动携带位置。因此,我在位置选项中定义了相同的soap url 例如:
谢谢您的时间。:) 这个解决方案对我有效 例如
$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, 'keep_alive' => false,'trace' => 1, 'exceptions' => 1, "connection_timeout" => 180, 'stream_context' => stream_context_create($opts) );
$client = new SoapClient({soapurl},$params);
//Remaining as the same above
$params = array('location' => {soapurl});
$client = new SoapClient({soapurl},$params);
$client = new SoapClient('https://example.com/webservice.php?wsdl');
$client->__setLocation('https://www.somethirdparty.com');