PHP Soap故障: Could not connect to host

标签 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:-->
         <pos:UserName>xxxxxxx</pos:UserName>
         <!--Optional:-->
         <pos:Password>yyyyyyyy</pos:Password>
      </pos:Authentication>
   </soap:Header>
   <soap:Body>
       .....
   </soap:Body>
</soap:Envelope>

PHP 代码:

$client = new SoapClient({soapurl},$params);
$auth = new stdClass();
$auth->UserName = 'xxxxxxx';
$auth->Password = 'yyyyyyyy'; 
$header = new SoapHeader('NAMESPACE','Authentication',$auth,false);
$client->__setSoapHeaders($header); 

$result = $client->__soapCall('{soap function}',array()); // when this line executes it throws me the error "Could not connect to the host"

请注意,My 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 时,它会给我一个响应。

最佳答案

最后,我得到了解决方案,

我发现了问题。我尝试连接的主机正在重定向到另一个域名。出于某种原因,PHP 5.6 不会自动携带该位置。所以我在位置选项中定义了相同的 soap url。

例如:

$params = array('location' => {soapurl});
$client = new SoapClient({soapurl},$params);

感谢您的宝贵时间。 :)

关于PHP Soap故障: Could not connect to host,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45403975/

相关文章:

delphi - 使整数属性为零

php - 如何停止 PHP SoapClient 转换 s1 :char arguments to 0 or 1 in request

C# 生成的 SOAP 客户端自定义转换器

php - twilio 动态语音 url 号码?

php - 在 2 个表中列出成员的所有内容(问题、答案)

php - 如何开始为php MVC自创框架写一个SDK

php - 如何在 php 中将重音字符转换为 html?

c# - 我应该使用哪个 header ? XMLHTTPRequest header 还是 SOAP header ?

java - 在一个数据包中发送多个 SOAP 请求

java - 带有 devtools 的 Spring Boot 调用 SOAP API