php curl not getting same response as fiddler -
this php code : $source = $_post['source']; $destination = $_post['destination']; $class = $_post['class']; $day = $_post['day']; $month = $_post['month']; $data = array( 'lccp_src_stncode_dis' => $source, 'lccp_dstn_stncode' => $destination, 'lccp_classopt' => $class, 'lccp_day' => $day, 'lccp_month' => $month ); # create connection $url = 'data per raw req '; $ch = curl_init($url); echo $ch." <br>"; # form info string $poststring = http_build_query($data); echo $poststring; $header = array ( 'host' => 'data per raw req ' 'connection'=> 'keep-alive', 'content-length'=> '180', 'cache-control'=> 'max-age=0', 'accept'=> 'text/html', 'origin'=> 'data per raw req ', 'user-agent' => '', 'content-type' => 'application/x-www-form-urlencoded', 'referer': 'data per raw req ' 'accept-encoding'=> '', 'accept-language' => 'en-us,en;q=0.8' ); # setting options curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_postfields, $poststring); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_httpheader, $header); //# response curl_setopt($ch, curlopt_postfields, $response = curl_exec($ch); curl_close($ch); #print response echo " $response ";
receiving form info from:
<html> <form method="post" action="poster.php"> <table> <tr><td>source:</td><td><input type="text" name="source"></td></tr> <tr><td>destination:</td><td><input type="text" name="destination"></td></tr> <tr><td>day:</td><td><input type="text" name="day"></td></tr> <tr><td>month:</td><td><input type="text" name="month"></td></tr> <tr><td>class:</td><td><input type="text" name="class"></td></tr> <tr><td><input type="submit" name="submit" value="submit"></td> <td><input type="reset" name="reset" value="reset"></td></tr> </table> </form> </html>
this raw request
post http://www.indianrail.gov.in/cgi_bin/inet_srcdest_cgi_date.cgi http/1.1 host: www.indianrail.gov.in connection: keep-alive content-length: 91 cache-control: max-age=0 accept: text/html origin: **<---modified since can't post more 2 links user-agent: content-type: application/x-www-form-urlencoded referer: ** <---modified since can't post more 2 links accept-encoding: accept-language: en-us,en;q=0.8 lccp_src_stncode_dis=ndls&lccp_dstn_stncode=hyb&lccp_classopt=sl&lccp_day=26&lccp_month=6
fiddler giving appropriate response cgi, whereas php script shows html container, i've been stuck on hr ! please help ! edit: output verbose :
* adding handle: conn: 0x2cab910 * adding handle: send: 0 * adding handle: recv: 0 * curl_addhandletopipeline: length: 1 * - conn 3 (0x2cab910) send_pipe: 1, recv_pipe: 0 * connect() www.indianrail.gov.in port 80 (#3) * trying 203.176.113.78... * connected www.indianrail.gov.in (203.176.113.78) port 80 (#3) > post /cgi_bin/inet_srcdest_cgi_date.cgi http/1.1 host: www.indianrail.gov.in accept: */* http://www.indianrail.gov.in http://www.indianrail.gov.in/know_station_code.html content-length: 89 content-type: application/x-www-form-urlencoded * upload sent off: 89 out of 89 bytes < http/1.1 200 ok < date: fri, 27 jun 2014 05:38:17 gmt * server apache/2.2.15 (red hat) not blacklisted < server: apache/2.2.15 (red hat) < connection: close < transfer-encoding: chunked < content-type: text/html; charset=utf-8 < * closing connection 3
^off topic: why did allow me post links time, should have been recognized links ?
also, compare sessions in fiddler, fiddler shows request own app on local host, not app indian railways site. screenshot : nevermind, not plenty rep edit: i'll happy if can show me how create request http_request2 i've posted exact raw request gives me required output fiddler in comments, no, i'm not missing authentication , cookie headers , like
header not entered associative array, wrong :
$header = array ( 'host' => 'data per raw req ' 'connection'=> 'keep-alive', 'content-length'=> '180', 'cache-control'=> 'max-age=0', 'accept'=> 'text/html', 'origin'=> 'data per raw req ', 'user-agent' => '', 'content-type' => 'application/x-www-form-urlencoded', 'referer': 'data per raw req ' 'accept-encoding'=> '', 'accept-language' => 'en-us,en;q=0.8' );
correct method :
$header = array ( 'host:*data per raw req* ' 'connection:keep-alive', 'content-length:180', 'cache-control:max-age=0', 'accept:text/html', 'origin:*data per raw req* ', 'user-agent:', 'content-type:application/x-www-form-urlencoded', 'referer:*data per raw req* ' 'accept-encoding:', 'accept-language:en-us,en;q=0.8' );
even info entered in associative array i've used formatted url encoded post string, apparently pretty much has entered in raw http request. curl doesn't formatting.
php curl fiddler
No comments:
Post a Comment