CURL HTTP / 1.1 403禁止日期 [英] CURL HTTP/1.1 403 Forbidden Date

查看:384
本文介绍了CURL HTTP / 1.1 403禁止日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$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设置。

Anything curl setting that would acceess to get the result.

推荐答案

许多服务器会仔细检查请求头,以确认人类发出请求(最好是从浏览器代理),而不是自动化过程。除了未经授权访问其资源的所有警告,您可以添加一些Accept标头以获得200响应。在这种情况下,我只能使用一个额外的标头获得200响应:

Many servers will check the request headers carefully to confirm that a human is making a request (preferably from a browser agent), rather than an automated process. All caveats aside about unauthorized access to their resources, you can add some Accept headers to get a 200 response. In this case, I was able to get a 200 response using only one additional header:

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

这篇关于CURL HTTP / 1.1 403禁止日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆