[英]cURL : “Couldn't connect to host”
I have solved that in the past, but I most definitely cannot remember how. 我过去已经解决了这个问题,但我绝对不记得是怎么回事。
So, I'm trying to fetch a webpage to my server, using a proxy. 所以,我正在尝试使用代理将网页提取到我的服务器。
Here is the code : 这是代码:
function curlFile($url,$proxy_ip,$proxy_port,$loginpassw)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_VERBOSE, false);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
$data = curl_exec($ch);
if(curl_errno($ch)){
echo 'Curl error: ' . curl_error($ch);
}
print_r(curl_getinfo($ch));
print_r(curl_error($ch));
print_r($data);
curl_close($ch);
return $data;
}
All it currently outputs is : 目前输出的全部是:
Curl error: couldn't connect to hostArray ( [url] => http://www.drkameleon.com [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.007872 [namelookup_time] => 0.007537 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 ) couldn't connect to host
卷曲错误:无法连接到hostArray([url] => http://www.drkameleon.com [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.007872 [namelookup_time] => 0.007537 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] = > 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0)无法连接到主机
So, any ideas? 那么,有什么想法吗? What could be going wrong?
怎么可能出错?
Your webserver is unable to connect to the proxy 您的网络服务器无法连接到代理
The proxy requires authentication? 代理需要身份验证吗? (You should have got a 4xx response from the proxy - if you've got CLI adccess try running curl from the comand line).
(您应该从代理获得4xx响应 - 如果您已获得CLI访问权限,请尝试从命令行运行curl)。
The proxy got a NXDomain on lookup or didn't get the IP address you were expecting. 代理在查找时获得了NXDomain,或者没有获得您期望的IP地址。
Execute the same script on an online PHP platform and see the result. 在在线PHP平台上执行相同的脚本并查看结果。 There might be a couple of issues
可能有几个问题
SSL verification problem. SSL验证问题。 If you are making a request to a HTTPS website and if your curl library is not configured to trust the certificates, you'll have a problem.
如果您向HTTPS网站发出请求,并且您的curl库未配置为信任证书,则会出现问题。 You can download the CA certificate of the other website and point the curl library in that direction.
您可以下载其他网站的CA证书,并将curl库指向该方向。
If you are on a university/office network, it might be a firewall issue. 如果您在大学/办公室网络上,则可能是防火墙问题。
Incorrect port configuration. 端口配置不正确。
Run the same script online and see what result you get for [ssl_verify_result]. 在线运行相同的脚本,查看[ssl_verify_result]的结果。 Also see the HTTP code at which it is pointing at.
另请参阅它所指向的HTTP代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.