Making POST request using PHP Curl not working -


i've read through solution don't think it's need - making post request using curl, not working

this api.php post it's long.

http://pastebin.com/8srk4nuu

this schedule.php

$pnt_no = isset($_post['trnno'])? $_post['trnno']:(isset($_get['trnno'])?$_get['trnno']:''); $rtype = isset($_post['rtype'])? $_post['rtype']:(isset($_get['rtype'])?$_get['rtype']:'');  //create array of data posted $post_data['lccp_trnname'] = $pnt_no; $post_data['getit'] = "wait pnr enquiry!"; //traverse array , prepare data posting (key1=value1) foreach ( $post_data $key => $value) {     $post_items[] = $key . '=' . $value; } //create final string posted using implode() $post_string = implode ('&', $post_items);  //create curl connection $curl_connection =   curl_init('http://www.indianrail.gov.in/cgi_bin/inet_trnnum_cgi.cgi'); //set option curl_setopt($curl_connection, curlopt_connecttimeout, 30); curl_setopt($curl_connection, curlopt_useragent,   "mozilla/4.0 (compatible; msie 6.0; windows nt 5.1)"); curl_setopt($curl_connection, curlopt_returntransfer, true); curl_setopt($curl_connection, curlopt_ssl_verifypeer, false); curl_setopt($curl_connection, curlopt_followlocation, 1); //set data posted curl_setopt($curl_connection, curlopt_postfields, $post_string); //perform our request $result = curl_exec($curl_connection); //show information regarding request //print_r(curl_getinfo($curl_connection)); //echo curl_errno($curl_connection) . '-' . //                curl_error($curl_connection); //close connection curl_close($curl_connection);  echo $result; //$matches = array(); //preg_match_all('/<td>(.+?)<\/td>/',$result,$matches); //var_dump($matches); 

i don't know why wont connect, other http://www.indianrail.gov.in/cgi_bin/inet_pnrstat_cgi.cgi doesn't exist can see, tried http://www.indianrail.gov.in/cgi_bin/inet_pnstat_cgi_24335.cgi didn't make difference

look @ http_build_query, better when manually string building
can use $_request array both , post queries...

here snippet post request:

<?php $post_data = array();  $pnt_no = isset($_request['trnno']) ? $_request['trnno']:''; $rtype = isset($_request['rtype'])  ? $_request['rtype']: '';  //create array of data posted $post_data['lccp_trnname'] = $pnt_no; $post_data['getit'] = "wait pnr enquiry!";  $url = 'http://www.indianrail.gov.in/cgi_bin/inet_trnnum_cgi.cgi'; $data = http_build_query($post_data); $ch = curl_init(); curl_setopt($ch,curlopt_url, $url); curl_setopt($ch,curlopt_post, count($post_data)); curl_setopt($ch,curlopt_postfields, $data); $result = curl_exec($ch); curl_close($ch);  echo $result;//web page "welcome indian railway passenger reservation enquiry" 

also make queries without curl:

<?php $data = array('http' =>     array(         'method'  => 'post',         'header'  => 'content-type: application/x-www-form-urlencoded',         'content' => $post_data     ) ); $context  = stream_context_create($data); $result = file_get_contents($url, false, $context); echo $result; 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -