php curl 出现403,PHP cURL导致403 Forbidden

我正在尝试cURL导致403 Forbidden错误的远程站点。从同一台服务器,我可以通过终端运行以下两个命令。第一个失败而第二个失败。如何让我的PHP代码与第二个终端命令相匹配?

此终端命令不会返回任何内容。

curl http://www.barneys.com

此终端命令会产生正确的结果(页面的HTML)

curl -L http://www.barneys.com

我的PHP代码:

$ch = curl_init('http://www.barneys.com');

$http_headers = array(

'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:40.0)' . 'Gecko/20100101 Firefox/40.0',

'Accept: */*',

'X-Requested-With: XMLHttpRequest',

'Referer: http://www.barneys.com', # IMPORTANT

'Accept-Language: pt-BR,en-US;q=0.7,en;q=0.3',

);

curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);

curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_AUTOREFERER, true);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_REFERER, 'http://www.barneys.com');

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);

curl_setopt($ch, CURLOPT_TIMEOUT, 60);

$response = curl_exec($ch);

$redirectURL = curl_getinfo($ch,CURLINFO_EFFECTIVE_URL);

curl_close($ch);

echo $response;

编辑:以下是来自cURL请求的PHP日志:

* About to connect() to www.barneys.com port 80 (#0)

* Trying 23.204.27.110... * connected

* Connected to www.barneys.com (23.204.27.110) port 80 (#0)

> GET / HTTP/1.1

Host: www.barneys.com

User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:40.0)Gecko/20100101 Firefox/40.0

Accept: */*

X-Requested-With: XMLHttpRequest

Referer: http://www.barneys.com

Accept-Language: pt-BR,en-US;q=0.7,en;q=0.3

Connection: keep-alive

< HTTP/1.1 403 Forbidden

< Server: AkamaiGHost

< Mime-Version: 1.0

< Content-Type: text/html

< Content-Length: 265

< Expires: Mon, 11 Apr 2016 23:22:16 GMT

< Date: Mon, 11 Apr 2016 23:22:16 GMT

< Connection: close

<

* Closing connection #0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值