/**
* https请求(支持GET和POST),且最长时间为30秒
* */
function
https_request($url,
$data
=
null
,$headers=null
,$method=null)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,
FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,
FALSE);
if
(!empty($method)){
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
//设置请求方式
}
if
(!empty($data)){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS,
$data);
}
if
(!empty($headers)){
// curl_setopt($curl, CURLOPT_HEADER, false);// 启用时会将头文件的信息作为数据流输出
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);//等待时间
$output = curl_exec($curl);
if
($output !==
false) {
}
else
{
$output = curl_errno($curl);
}
curl_close($curl);
return
$output;
}
/**
* curl获取内容,且最长时间为5秒
* */
function
curHtml($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
return
curl_exec($ch);
curl_close($ch);
}
458

被折叠的 条评论
为什么被折叠?



