Php 不支持HTTP/1.1 505 HTTP版本

Php 不支持HTTP/1.1 505 HTTP版本,php,http,file-get-contents,Php,Http,File Get Contents,我正在运行一个PHP脚本来抓取一个网页。它在许多站点上运行良好,但在一个站点上运行失败,返回一个错误“HTTP/1.1505 HTTP版本不受支持” 这是我的剧本的一部分: for($i = 0; $i < 1; $i++) { $page = file_get_contents("http://www.lovelybooks.de/stoebern/empfehlung/romantic fantasy/?seite=$i"); // do something with

我正在运行一个PHP脚本来抓取一个网页。它在许多站点上运行良好,但在一个站点上运行失败,返回一个错误“HTTP/1.1505 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
}
请求标头:

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

还有什么问题吗?

我看到您在URL中使用了空格。那不行 为了解决这个问题,我将url放入另一个变量中,并对其进行如下编码:

$URL = urlencode("http://www.lovelybooks.de/stoebern/empfehlung/romantic fantasy/?seite=".$i);

file_get_contents($URL);

将URL中的空格替换为其百分比编码:

    $page = file_get_contents("http://www.lovelybooks.de/stoebern/empfehlung/romantic%20fantasy/?seite=$i");

不要对整个事情进行编码。这将对
://
内容进行编码,这将阻止PHP对其进行解析。lol,谢谢。我知道URL编码可能有问题,但没有看到URL中的空格,因为它“隐藏”在由编辑器窗口的宽度引起的换行符中。我刚刚把“%20”放在那个空格的位置,就这样做了。谢谢,我这样做了(请参阅我对另一个答案的评论)。愚蠢的我。
    $page = file_get_contents("http://www.lovelybooks.de/stoebern/empfehlung/romantic%20fantasy/?seite=$i");