博客列表 >PHP curl 访问https URL 武汉

PHP curl 访问https URL 武汉

php开发大牛
php开发大牛原创
2018年04月18日 17:10:50735浏览

需开启open_ssl扩展

function curl_string ($url,$user_agent,$proxy){

$ch = curl_init();
curl_setopt ($ch, CURLOPT_PROXY, $proxy);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_AUTOREFERER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_COOKIEJAR, "c:\\cookie.txt");
curl_setopt ($ch, CURLOPT_HEADER, 1);curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 320);
$result = curl_exec ($ch);
curl_close($ch);
return $result;
}

$url_page = "https://www.google.com.hk/?gws_rd=cr";
//$url_page = "https://github.com/";
$user_agent = "Mozilla/4.0";
$proxy = "https://127.0.0.1:8087";
$string = curl_string($url_page,$user_agent,$proxy);
echo($string);// $string;
var_dump($string);
//echo file_get_contents("$url_page");
exit;


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议