1
我們有一個任務來過濾來自機器人的真實捲曲請求。我向該網站發送了一個curl請求,但是它向我返回了一個無效的圖像文件(我知道,因爲當我用我的瀏覽器查看它時,它工作)。它以某種方式知道我的請求不是真實的。我在這裏忽略了一個字段,我試圖完全模仿瀏覽器請求。用於捲曲請求的瀏覽器標頭
$header_arr = array(
'0' =>'Host: www.myittest.com',
'1' =>'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0',
'2' =>'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*\/*;q=0.8',
'3' =>'Accept-Language: en-US,en;q=0.5',
'4' =>'Accept-Encoding: gzip, deflate',
'5' =>'Connection: keep-alive',
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_arr);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 6);
$raw=curl_exec($ch);
嘗試'$ ch = curl_init(); curl_setopt($ ch,CURLOPT_URL,$ url);'而不是'$ ch = curl_init($ url);' – 2014-11-04 05:43:47