簡體   English   中英

在AWS Elastic Beanstalk中訪問被拒絕的php curl

[英]Access denied php curl in AWS Elastic Beanstalk

我有一個使用curl來訪問外部URL並分析頁面內容的PHP應用程序。 我的代碼在localhost上運行良好,但是當我將其運行在服務器上時顯示錯誤:

拒絕訪問

您無權訪問此服務器上的“ 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);

任何想法?

EC2的IP范圍經常被阻止對某些站點進行爬網,包括StackOverflow。

該代碼對我有用。 您可能需要在AWS實例上打開端口80。 您可以通過編輯與Elastic Beanstalk創建的實例相關聯的安全組來實現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM