我正在运行一个PHP脚本来获取网页。它可以很好地处理许多网站,但是在某个网站上失败了,返回一个错误,指出“HTTP/1.1 505 HTTP版本不受支持”。
这是我的脚本的一部分:
for($i = 0; $i < 1; $i++) {
$page = file_get_contents("http://www.lovelybooks.de/stoebern/empfehlung/romantic fantasy/?seite=$i");
// do something with $page
}
很多答案建议明确设置HTTP版本。我已经尝试设置0.9、1.0和1.1,但没有改变任何东西。实际上,标头似乎显示我的浏览器请求的HTTP版本与服务器期望的版本相匹配:
回复标头:
HTTP/1.1 200 OK
Date: Mon, 15 Dec 2014 09:01:15 GMT
Server: Apache
X-Powered-By: PHP/5.4.35
Keep-Alive: timeout=2, max=200
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
请求头:
GET /path/script.php HTTP/1.1
Host: www.mydoman.de
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:34.0) Gecko/20100101 Firefox/34.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Authorization: Basic MjQwMjE5Njc6MDcwNjIwMDc=
Connection: keep-alive
Cache-Control: max-age=0
还可能有什么问题?