我想通过浏览器获取网页的结果,就像一个简单的用户一样。我设置了请求的标题和发送的cookie,我用fiddler4得到了它。昨晚它起了作用,但现在它发出cURL错误28,请求超时。
以下是我使用的代码:
function cURL($url){
$cURL=curl_init();
$header[0] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: hu-HU,hu;q=0.8,en-US;q=0.6,en;q=0.4,es;q=0.2,it;q=0.2,de;q=0.2,fr;q=0.2";
$header[] = "Accept-Encoding: gzip, deflate, sdch";
$header[] = "Pragma: ";
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_USERAGENT, 'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36');
curl_setopt($cURL, CURLOPT_HTTPHEADER, $header);
curl_setopt($cURL, CURLOPT_POST, true);
curl_setopt($cURL, CURLOPT_POSTFIELDS, 'action=verChau');
curl_setopt($cURL, CURLOPT_REFERER, 'http://www.google.com');
curl_setopt($cURL, CURLOPT_AUTOREFERER, true);
curl_setopt($cURL, CURLOPT_COOKIE, 'Cookie: __gfp_64b=mgK79a4qc_M9RH4eFToSbGkkxUWaWD2tKPQ51RreN8r.A7; PHPSESSID=780d83cb35c5b82098e33fde9c101d08; __atuvc=0%7C4%2C0%7C5%2C1%7C6%2C6%7C7%2C1%7C8; cTest=1; resDone20101213=1; _gat=1; _ga=GA1.2.307256553.1418233339; _goa3=eyJ1IjoiMTQxMjEyNDEwODM2NDE4MTU4NzAxNiIsImgiOiJCQzI0OEVFRC5kc2wucG9vbC50ZWxla29tLmh1IiwicyI6MTQxODMzODgwMDAwMH0=; _goa3TC=eyI1NjM2NCI6MTQyNTEzMjMwNDE2OCwiMzEzNDUzMiI6MTQyNTE0ODk1NDg2M30=; _goa3TS=e30=');
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURL, CURLOPT_TIMEOUT, 10);
$html=curl_exec($cURL);
if ($html === false){
echo "cURL exception: ".curl_errno($cURL).": ".curl_error($cURL);
}
curl_close($cURL);
return $html;
}
有人可以帮帮我吗?