【问题标题】:PHP Soap Fault: Could not connect to hostPHP Soap 故障:无法连接到主机
【发布时间】:2017-07-30 19:43:00
【问题描述】:

有很多类似的问题。但是尝试时我没有得到解决方案。在下面找到我的代码:

肥皂 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"

请注意,我的 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 soap soap-client


    【解决方案1】:

    终于找到解决办法了,

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

    例如:

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

    感谢您的宝贵时间。 :)

    【讨论】:

      【解决方案2】:

      这个解决方案对我有用。

      例如

      $client = new SoapClient('https://example.com/webservice.php?wsdl');
      
      $client->__setLocation('https://www.somethirdparty.com');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-19
        相关资源
        最近更新 更多