当前位置:Gxlcms > PHP教程 > phpcurlcouldn'tconnecttohost

phpcurlcouldn'tconnecttohost

时间:2021-07-01 10:21:17 帮助过:7人阅读

        $url = 'http://xxx.net';
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_CUSTOMREQUEST => "GET",
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);

        if ($err) {
            return "cURL Error #:" . $err;
        }
        return $response;

xxx.net 是本地绑定的Host
浏览器访问是正常的
php curl 就couldn't connect to host

回复内容:

        $url = 'http://xxx.net';
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_CUSTOMREQUEST => "GET",
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);

        if ($err) {
            return "cURL Error #:" . $err;
        }
        return $response;

xxx.net 是本地绑定的Host
浏览器访问是正常的
php curl 就couldn't connect to host

你用的什么环境啊?

人气教程排行