简体   繁体   中英

Access denied php curl in AWS Elastic Beanstalk

I have a PHP application that uses curl to access an external url and analyze the content of the page. My code worked perfectly on localhost but when I put it to run on the server displays the error:

Access Denied

You don't have permission to access " http://www.example.com " on this server. Reference #18.aec67bc8.1417892829.438558f

My code

$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);

Any idea?

EC2的IP范围经常被阻止对某些站点进行爬网,包括StackOverflow。

The code works for me. You probably need to open port 80 on your AWS instance. You can do that by editing the Security Group associated with the instance created by Elastic Beanstalk.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM