php curl https请求 _爱资料
主页 > 编程资料 > PHP >
发布时间:2015-12-28 作者:apizl 阅读:164次
有时候我们需要请求谷歌https的数据 或者其他接口的数据 、这个时候就需要使用curl https了
echo curlhttps("https://www.google.com");
function curlhttps($url){    
    $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);
    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  // this line makes it work under https
    $result=curl_exec ($ch);
    curl_close ($ch);
    return $result;
}


文章由爱资料原创本文地址:https://www.apizl.com/archives/view-40825-1.html,转载请以链接形式标明本文地址!
关键字词: