我在PHP Curl中收到此错误
* Hostname in DNS cache was stale, zapped
* Trying xxx.xx.x.xx...
* connect to xxx.xx.x.xx port 4005 failed: Connection refused
* Failed to connect to sample.website.net.au port 4005: Connection refused
* Closing connection 0
我有这段代码:
$ch = curl_init();
$headers = array(
'Content-type: text/xml',
'charset: utf-8',
'SOAPAction: urn:ServiceQualification#AddresSsearch',
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$verbose = fopen('php://temp', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $verbose);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); // This should always be set to 'TRUE' when in production to ensure the SSL is enabled.
$response = curl_exec ($ch);
if ($result === FALSE) {
printf("cUrl error (#%d): %s<br>\n", curl_errno($ch),
htmlspecialchars(curl_error($ch)));
}
rewind($verbose);
$verboseLog = stream_get_contents($verbose);
echo "Verbose information:\n<pre>", htmlspecialchars($verboseLog), "</pre>\n";
curl_close ($ch);
return $response;
我不知道为什么我会遇到这个错误。我在我的localhost中尝试了这个,它运行得很好,但当我将它上传到我的服务器时,我得到了所谓的php curl错误。
这里似乎有什么问题?我是否需要联系我尝试连接的网址?
我现在正在敲打你的头,非常感谢你的帮助。
谢谢!
答案 0 :(得分:0)
拒绝连接:
检查您是否可以将传出连接到端口4005.可能是您的防火墙阻止了您。
检查您是否可以将传出连接到端口4005.可能是阻止您的远程防火墙。
检查您是否可以通过终端ping远程主机:
ping 1.2.3.4 // this is the ip, you can also use the hostname.
尝试通过终端连接远程主机和特定端口:
telnet 1.2.3.4 4005
这比通过php代码调试更容易。