dimanche 5 avril 2015

php curl trying to submit form

I have very simple HTML file:



<form action="http://ift.tt/1IAn9xq" method="post">
<input name="CltCode" value="012000280201">
<input name="IDNumber" value="14236969">
<input name="amount" value="">
<input name="frameModel" value="1">
<input name="hdnIsMobile" value="no">
<input name="hdnserid" value="347">
<input name="hdnSubServiceName" value="">
<input name="hdnSubServiceValue" value="">
<input type="submit">
</form>


When I click Submit button e-pul.az's server return's me this json:



{"code":"Ok","message":null,"fullName":"ƏMİRASLANLI AYXAN FÜZULİ OĞLU","debt":0.0,"hasDebtProperty":true,"subServices":[],"additionalInfo":[]}


THE CODE IS OK!


So this is my PHP part. Now I am trying to post this data with PHP:



<?php
$tmpfname = 'cookie.txt';
function posttoscript($url,$data)
{
global $tmpfname;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_REFERER, 'http://ift.tt/1xReGp9');
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json, text/javascript, */*; q=0.01',
'Accept-Encoding: gzip, deflate',
'Accept-Language: en-US,en;q=0.8,az;q=0.6,ru;q=0.4,tr;q=0.2,es;q=0.2',
'X-Requested-With: XMLHttpRequest',
'Content-Length: 126',
'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
'Origin: https://www.e-pul.az',
'Connection: keep-alive',
'Host: www.e-pul.az'
));

$response = curl_exec($ch);
if ($response === false)
{
echo 'Error: '.curl_error($ch).'';
die;
}
return $response;
}
$data['CltCode'] = $clientid;
$data['IDNumber'] = $passport;
$data['amount'] = '';
$data['frameModel'] = '1';
$data['hdnIsMobile'] = 'no';
$data['hdnserid'] = '';
$data['hdnSubServiceValue'] = '';
$data = http_build_query($data);
$url = 'http://ift.tt/1IAn9xq';
$post = posttoscript($url,$data);
echo $post;
?>


Now this code returns me this JSON:



{"code":"Error","message":"Müştəri tapılmadı","fullName":null,"debt":0.0,"hasDebtProperty":false,"subServices":[],"additionalInfo":[]}


QUESTION: WHERE IS MY MISTAKE?


Aucun commentaire:

Enregistrer un commentaire