且构网

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

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

更新时间:2021-12-13 22:37:16


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页面,则... / code>或您有一些防火墙限制问题。

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