为了检查HTTP响应标头中的一组URL,我使用curl发送了以下请求标头
foreach ( $urls as $url )
{
// Setup headers - I used the same headers from Firefox version 2.0.0.6
$header[ ] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[ ] = "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$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: en-us,en;q=0.5";
$header[ ] = "Pragma: "; // browsers keep this blank.
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header);
curl_setopt( $ch, CURLOPT_REFERER, 'http://www.google.com');
curl_setopt( $ch, CURLOPT_HEADER, true );
curl_setopt( $ch, CURLOPT_NOBODY, true );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY );
curl_setopt( $ch, CURLOPT_TIMEOUT, 10 ); //timeout 10 seconds
}
有时我收到200 OK,这在其他时候也不错,在我认为还不错的301、302、307上,但是在其他时候,我收到的奇怪状态是406、500、504,它们应该标识无效的网址,但是当我在浏览器中打开它们时没事
例如脚本返回
http://www.awe.co.uk/ => HTTP/1.1 406 Not Acceptable
和wget返回
wget http://www.awe.co.uk/
--2011-06-23 15:26:26-- http://www.awe.co.uk/
Resolving www.awe.co.uk... 77.73.123.140
Connecting to www.awe.co.uk|77.73.123.140|:80... connected.
HTTP request sent, awaiting response... 200 OK
有人知道我缺少哪个请求标头或添加了过多的请求标头吗?