且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何解决 cURL 错误 (7): 无法连接到主机?

更新时间:2021-12-05 22:24:28

CURL 错误代码 7 (CURLE_COULDNT_CONNECT)

CURL error code 7 (CURLE_COULDNT_CONNECT)

非常明确......这意味着无法连接()到主机或代理.

is very explicit ... it means Failed to connect() to host or proxy.

以下代码适用于任何系统:

The following code would work on any system:

$ch = curl_init("http://google.com");    // initialize curl handle
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
print($data);

如果您看不到 google 页面,则 .. 您的网址错误 或者您有一些 firewallrestriction 问题.

If you can not see google page then .. your URL is wrong or you have some firewall or restriction issue.