各位大牛,小辈最近遇到一个奇怪的问题:我们公司是网通的运营商,为何我在公司局域网内部主机的桌面浏览器上可以打开位于如下电信服务器上的链接http://www.bundpic.com/ 但是,用libcurl来抓取的时候,却失败了,显示:
《外滩画报》在抓取主页过程中失败,显示如下信息:
[root@localhost html]# php curl_test.php
* getaddrinfo(3) failed for www.bundpic.com:80
* Couldn't resolve host 'www.bundpic.com'
* Closing connection #0
fail to fetch the response of the specified url ===> http://www.bundpic.com/ 经网上查看,是电信的dns出了问题。可是为何桌面浏览器可以看呢?下面是我的curl代码:<?php
    $url = 'http://www.bundpic.com/';

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_VERBOSE, 1); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_ENCODING, "");
curl_setopt ($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.12 (KHTML, like Gecko) Maxthon/3.4.2.3000 Chrome/18.0.966.0 Safari/535.12
"); 

$response = curl_exec($curl);
if (!$response)
{
echo 'fail to fetch the response of the specified url ===> '.$url.' <br />';
}
else
{
$offset = strpos($response, "\r\n\r\n");
$http_response_header = substr($response, 0, $offset);
$http_response_body = substr($response, $offset + 4);
echo $http_response_header.'<br />';
echo $http_response_body.'<br />';
}

curl_close($curl);

?>