curl gives 403 error? curl gives 403 error? curl curl

curl gives 403 error?


For my specific project, the server would throw a 403 error if an error occurs, but still return data. So to get around the issue, I did this:

curl_setopt($ch, CURLOPT_FAILONERROR, 0); // Fail on errors

If you disable the fail on errors, you might still get some data back. Hope that helps.


I'd suspect the justification for this is explicitly to stop automated behaviour - an anti-bot or general security measure. You may wish to look at the source code of the destination site and check for any such measures - a quick search of the code for '403' might offer some insight. It may even be the case that POST requests are not legitimate in that context - and thus prevented for security reasons.

I'm not sure what you mean by 'for security reasons' by the way. POST isn't more secure than GET. They're both open to just as much scrutiny.


My solution for this was to set the User Agent option, so the cURL can pretend to be a browser . An example of this set up in php is

curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6');

References: