function curlRequest($url, $params, $is_post = false, $time_out = 10, $header)
{
$str_cookie = isset($ext_params['str_cookie']) ? $ext_params['str_cookie'] : '';$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0);//设置是否返回response header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
//当需要通过curl_getinfo来获取发出请求的header信息时,该选项需要设置为true
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $time_out);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $time_out);
curl_setopt($ch, CURLOPT_POST, $is_post);
if ($is_post) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
}
if ($str_cookie) {
curl_setopt($ch, CURLOPT_COOKIE, $str_cookie);
}
if ($header) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
封装的curl 支持get post header
最新推荐文章于 2025-04-19 21:48:24 发布