我用php中的socket函数编了一段程序,主要功能是把一些网站的网页抓下来,但不知为什么只能将校园网内站点的网页扒下来,校园网外的就不行了,代码如下
<?php
$server="www.sina.com.cn";
$data=" ";
$query="GET / HTTP/1.0 \r\n Accept : */* \r\n\r\n";
$fp=fsockopen($server,80);
if($fp){
fputs($fp,$query);
while(!feof($fp)){
$data.=fread($fp,1000);
}
fclose($fp);
}
else{
echo "Can not open socket!";
}
echo $data
?>
下面为返回的错误信息
HTTP/1.0 503 Service Unavailable Server: squid/2.5.STABLE1 Mime-Version: 1.0 Date: Wed, 20 Aug 2003 06:17:03 GMT Content-Type: text/html Content-Length: 1049 Expires: Wed, 20 Aug 2003 06:17:03 GMT X-Squid-Error: ERR_CONNECT_FAIL 111 X-Cache: MISS from WebCache1 Connection: close
ERROR
The requested URL could not be retrieved
While trying to retrieve the URL:
http://202.118.170.105/
The following error was encountered:
* Connection Failed
The system returned:
(111) Connection refused
The remote host or network may be down. Please try the request again.
Your cache administrator is webmaster.
Generated Wed, 20 Aug 2003 06:17:03 GMT by WebCache1 (squid/2.5.STABLE1)
其中
http://202.118.170.105/不是新浪的IP(好像是教育网的IP),我们是通过校园网和外网连接的,不知是不是跟网络的DNS或网关有关呢