我有一個PHP應用程序,它使用curl訪問外部URL並分析頁面的內容。我的代碼工作完全在本地主機上,但是當我把它在服務器上顯示運行錯誤:在AWS中拒絕訪問php curl Elastic Beanstalk
Access Denied
You don't have permission to access " http://www.example.com " on this server. Reference #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)。 – Tal 2014-12-07 06:04:00