[英]PHP Calling Soap Method Error [Could not connect to host]
I have move my site to another server. 我已将网站移至另一台服务器。 After moving I've started to get Soap error as "Could not connect to host".
移动后,我开始收到Soap错误,提示为“无法连接到主机”。 The service I try to connect uses https protocol.
我尝试连接的服务使用https协议。
Old server's PHP version : 5.4 New server's PHP version : 5.6.16 旧服务器的PHP版本:5.4新服务器的PHP版本:5.6.16
There is no error in connection and I successfully connect to server that I wrote codes below : 连接没有错误,我成功连接到我在下面编写代码的服务器:
try {
$client = new SoapClient('https://www.example.com', [
'trace' => 1,
'stream_context'=> stream_context_create(['ssl'=> array('verify_peer'=>false, 'verify_peer_name'=>false)])
]);
} catch (SoapFault $sf) {
echo $sf->getMessage();
}
But I got error after calling a method : 但是调用方法后出现错误:
try {
$response = $client->method($parameter);
} catch (SoapFault $sf) {
echo $sf->getMessage();
}
Result of this code : "Could not connect to host". 此代码的结果:“无法连接到主机”。
How can I solve this problem? 我怎么解决这个问题? Many thanks for your interest in advance.
非常感谢您的提前关注。
Set this values in your file. 在文件中设置此值。
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
ini_set('soap.wsdl_cache_ttl',0);
Try to check your connection by this way also:- 尝试通过这种方式检查您的连接:
file_get_contents("https://www.example.com");
Try this way also:- 也尝试这种方式:-
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "https://www.example.com");
$result = curl_exec($ch);
curl_close($ch);
If all above solutions are not working then write this lines:- 如果以上所有解决方案均无效,请编写以下代码:-
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$response = file_get_contents("https://www.example.com", false, stream_context_create($arrContextOptions));
echo $response;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.