【发布时间】:2015-02-04 18:36:59
【问题描述】:
我有一个 PHP 应用程序,它使用 curl 访问外部 url 并分析页面内容。我的代码在本地主机上运行良好,但是当我把它放在服务器上运行时显示错误:
访问被拒绝
您无权在此访问“http://www.example.com” 服务器。参考#18.aec67bc8.1417892829.438558f
我的代码
$cookie_file = '';
$post_fields = 'id=1';
$agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com');
curl_setopt($ch, CURLOPT_USERAGENT,$agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
$output = curl_exec($ch);
有什么想法吗?
【问题讨论】:
-
知道哪个网站阻止了您会很有帮助。基本上该站点拒绝了您的 HTTP 请求,可能是 IP 或假用户代理(不能来自 EC2)。
标签: php curl amazon-web-services amazon-elastic-beanstalk