php - 亚马逊 AWS 拒绝 cURL 访问
问题描述
尝试使用 cURL 下载网络摄像头图像。
以下返回访问被拒绝:
<?php
$url = 'http://s3-us-west-2.amazonaws.com/alertwildfire-data-public/Axis-CupertinoHills/latest_full.jpg';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
header('Content-type: image/jpeg');
echo $data;
URL 来自此链接:
http://www.alertwildfire.org/index.html
选择区域然后查看网络摄像头并右键单击以查看图像。
解决方案
您需要设置适当的“Referer”标头
例子:
curl_setopt($ch, CURLOPT_REFERER, "http://www.alertwildfire.org/blmnv/index.html?camera=Axis-Angel&v=81e002f");
或者
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Referer: http://www.alertwildfire.org/blmnv/index.html?camera=Axis-Angel&v=81e002f'
));
推荐阅读
- amazon-web-services - AWS SQS FIFO 队列仍然要求消费者是幂等的?
- python - 将华氏度转换为摄氏度不断获得 0 的列表?
- sql - 查询中小时的平均数据
- c++ - 有没有其他方法可以在不使用数组的情况下按升序或降序对数字进行排序?
- java - 安卓。如果 json 无效,请不要解析它的值
- apache-kafka - Kafka 在春季流式传输,恰好一次 ACL 出现问题:TransactionalIdAuthorizationException
- java - 错误只有 OUT 参数的 Spring JPA 调用过程
- python - 如何在python的散点图中添加具有不同标记的多个图例?
- jsf - 如何聚焦使用 p:ajax 更新的字段?
- javascript - (VueJs) 我不能在 vuejs 中使用方法?