我已使用此代码打开 whatismyipaddress.com
$fp = fsockopen("whatismyipaddress.com", 80, $errno, $errstr, 5);
if ($fp) {
$url = "/";
fputs($fp, "GET $url HTTP/1.1\r\nHost: {whatismyipaddress.com}\r\nConnection: close\r\n\r\n");
$resp = '';
while(!feof($fp)) {
$resp .= fgets($fp, 1024);
}
echo "$resp";
}
我总是能看到这个错误
HTTP/1.1 301 Moved Permanently Date: Tue, 29 Nov 2011 20:19:36 GMT Server: Apache/2.2.17 (Unix) DAV/2 Location: http://whatismyipaddress.com/ MS-Author-Via: DAV Content-Length: 0 Connection: close Content-Type: text/html
我也使用此代码打开
whatismyipaddress.com/proxy-check
$fp = fsockopen("whatismyipaddress.com", 80, $errno, $errstr, 5);
if ($fp) {
$url = "/proxy-check";
fputs($fp, "GET $url HTTP/1.1\r\nHost: {whatismyipaddress.com}\r\nConnection: close\r\n\r\n");
$resp = '';
while(!feof($fp)) {
$resp .= fgets($fp, 1024);
}
echo "$resp";
}
并有这个错误
HTTP/1.1 404 Not Found Date: Tue, 29 Nov 2011 20:32:07 GMT Server: Apache/2.2.17 (Unix) DAV/2 Content-Length: 421 Connection: close Content-Type: text/html; charset=iso-8859-1 Not Found
The requested URL /proxy-check was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. Apache/2.2.17 (Unix) DAV/2 Server at {whatismyipaddress.com} Port 80
我敢肯定,代码没有任何问题。我已经在许多网站上对其进行了测试,我没有遇到任何问题
请问谁能解释一下这个问题?
谢谢你。
最佳答案
我会尝试在标题中使用另一个用户代理。
我确信他们正在使用某种基于 header 的保护来阻止机器人。
使用 curl :
$ curl -I 'http://whatismyipaddress.com'
HTTP/1.1 403 Forbidden
Date: Tue, 29 Nov 2011 20:48:28 GMT
Server: Apache/2.2.17 (Unix) DAV/2
Vary: Accept-Encoding
Connection: close
Content-Type: text/html; charset=iso-8859-1
但是,一旦尝试强制用户代理,它就可以工作:
$ curl -I -A 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0.1) Gecko/20100101 Firefox/8.0.1' 'http://whatismyipaddress.com'
HTTP/1.1 200 OK
Date: Tue, 29 Nov 2011 20:49:24 GMT
Server: Apache/2.2.17 (Unix) DAV/2
Set-Cookie: pt=f737a9bb1a119dcec75073f11b05d213; expires=Wed, 30-Nov-2011 20:49:24 GMT
MS-Author-Via: DAV
Vary: Accept-Encoding
Content-Type: text/html
关于php - fsockopen 有错误 : HTTP/1. 1 301 Moved Permanently 和 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8317464/