2
有許多類似的問題。但是我嘗試時沒有得到解決方案。找到我的代碼如下:PHP Soap Fault:無法連接到主機
肥皂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"
請注意,我的肥皂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嘗試它給了我一個答覆。