cURL - works in browser, not in cURL cURL - works in browser, not in cURL curl curl

cURL - works in browser, not in cURL


Problem solved.
It was a matter of using the correct headers.Following the reports from the browser, I went through all steps and the result showed up.

I went through each step by using:

curl_initcurl_setopt()..curl_setopt()curl_exec()curl_close()

This way I had to manually set each request and go through the settings. It made the code longer, but much easier to understand.

I had thoughts about the site using some javascript special code to make the site work, so I was troubled a lot by all the extra, javascript code, which turned out unnecessary.

It was all about being alot more organized and following the correct header settings.

Moreover, since this was an ASPX site, I had to read and memorize the VIEWSTATE and VALIDATION of the last page in each iteration. That is the first and very reason for the 500 internal error server message I used to get all the time.

I used Firebug and LiveHttpHeaders to concolude each step.


"Can't get that to even start to work. It starts with returning me a 200 OK, instead of 302, and sometimes I also get a 500."

curl_setopt($curl, CURLOPT_FOLLOWLOCATION  ,1);

You have Curl set to follow any 302 redirects. These will be followed internally inside of Curl and won't be seen by PHP.

Also:

curl_setopt($curl, CURLOPT_HEADER      ,1);  // DO NOT RETURN HTTP HEADERS

The comment does exactly the opposite of what the code does....which seems wrong.


before u made cURL, u need to review the requeste field used. usually HTTP 500 from aspx is not found the field send..

foreach($postarr as $key=>$value) {   $fields_string .= $key.'='.$value.'&';   echo" $fields_string <br> ";}

make sure, that field are not dinamic when u r sending request.. Hope this helpfull..