mardi 27 décembre 2016

POST is working in Fiddler but not in cURL

I have ran into a really wierd issue and have wasted several days on it and would like to see if anyone else has had similar issues.

I was writing a script in PHP to gather data with cURL. Everything is working good, I am able to login and get some data(with session already initiated).

But when I am trying to execute one specific POST request I get an error. Now one might think there's an error obviously. So I took EXACTLY the same http query and EXACTLY the same POST header and put it in Fiddler Composer, everything is working fine there, without any issues.

So exactly the same variables + query works on Fiddler, doesn't work in cURL.

On cURL I am receiving an error from webpage.

On Fiddler I am receiving the data I need.

This is my cURL request (obviously I have replaced the real website with a fake one)

function httpPostGetDataLink($url,$sesvar1,$sesvar2, $sesvar3, $sesvar4, $params){
$ch = curl_init();  
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Host: website", 
"Connection: keep-alive",
'Cache-Control: no-cache', 
'Origin: https://website', 
'X-Requested-With: XMLHttpRequest',
'X-MicrosoftAjax: Delta=true',
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
'Accept: */*',
'Referer: https://website/',
"Accept-Encoding: gzip, deflate, br",
'Accept-Language: en-US,en;q=0.8',
'Content-Length: ' . strlen($params),
"Cookie: $sesvar1; $sesvar2; $sesvar3; $sesvar4"
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);   
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$output=curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($output, 0, $header_size);
$body = substr($output, $header_size);
curl_close($ch);
$arr['header'] = $header;
$arr['body'] = $body;
return $arr;
}




Aucun commentaire:

Enregistrer un commentaire