$url = "http://search.aol.com/aol/search?q=hello";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
$html = curl_exec($ch);
curl_close($ch);
echo $html;
此回报:
HTTP/1.1 403 Forbidden
Forbidden
You don't have permission to access /aol/search on this server.
任何可以获取结果的curl设置。
答案 0 :(得分:3)
许多服务器会仔细检查请求标头,以确认人员正在发出请求(最好是来自浏览器代理),而不是自动过程。除了未经授权访问其资源之外,您可以添加一些Accept标头以获得200响应。在这种情况下,我只能使用一个额外的标题获得200响应:
curl -i \
-H 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
-H 'User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11' \
http://search.aol.com/aol/search?q=hello
答案 1 :(得分:0)
看起来AOL不希望任何人在他们的引擎上运行自动搜索。
大流士