最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP cURL初始化和執(zhí)行方法入門級(jí)代碼

 更新時(shí)間:2015年05月28日 15:20:01   投稿:junjie  
這篇文章主要介紹了PHP cURL初始化和執(zhí)行方法入門級(jí)代碼,本文直接給出代碼示例,代碼中包含詳細(xì)注釋,需要的朋友可以參考下

這個(gè)是采集基礎(chǔ),最好熟悉一下

$ch = curl_init();
# 設(shè)定url和把結(jié)果返回,是否返回頭部
curl_setopt($ch, CURLOPT_URL, 'http://www.baidu.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->ch, CURLOPT_HEADER, 1);

# cookie文件設(shè)定
curl_setopt($this->ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($this->ch, CURLOPT_COOKIEFILE, $cookie_file);

# 額外頭部
curl_setopt($this->ch, CURLOPT_HTTPHEADER, array('User-Agent: Mozilla/5.0'));

# 設(shè)定post
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $poststring);

# 連接、執(zhí)行過期時(shí)間
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 30);

# 是否跟隨301 302
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($this->ch, CURLOPT_MAXREDIRS, 10);

# refer
curl_setopt($this->ch, CURLOPT_REFERER, $refer);

# http版本和端口重用設(shè)置
curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($this->ch, CURLOPT_FORBID_REUSE, 1);

# 支持https
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);

# 如果需要進(jìn)行毫秒超時(shí),需要增加:
curl_setopt($this->ch, CURLOPT_NOSIGNAL, 1);

# 執(zhí)行
$response = curl_exec($ch);
if(curl_errno($ch)){
  curl_error($ch);
  exit();
}
curl_close($ch);

相關(guān)文章

最新評論

七台河市| 乐至县| 高邮市| 四子王旗| 汝南县| 前郭尔| 金寨县| 呼玛县| 启东市| 建水县| 铜川市| 贵德县| 景谷| 肃北| 天全县| 宜丰县| 六安市| 乌审旗| 清水县| 道孚县| 临海市| 遵化市| 射洪县| 沈阳市| 皋兰县| 綦江县| 隆回县| 抚州市| 陇西县| 肥城市| 抚顺县| 正安县| 故城县| 黑水县| 台湾省| 方城县| 武功县| 蛟河市| 丰顺县| 峨山| 图们市|