我想要一个POST请求,在此页面上获取车次时间表:http://www.indianrail.gov.in/train_Schedule.html使用curl使POST请求,没有工作
我使用这个代码,但它无法正常工作。由此产生的错误在下面附件中显示。 可能是什么问题?
PS:我使用Firebug
$data = array('lccp_trnname' => '14553', 'getIt' => 'Get Schedule');
$ch = curl_init();
$useragent= "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); // set user agent
curl_setopt($ch, CURLOPT_URL, 'http://www.indianrail.gov.in/cgi_bin/inet_trnnum_cgi.cgi');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$txResult = curl_exec($ch);
print "$txResult\n";
得到了CGI路径和参数在$数据:
http://www.indianrail.gov.in在网站上使用是非法的。而你的URL也wrong.FAILED IN CHK ENV 0埃罗RIS有 – sandeep 2012-03-14 10:43:11
也添加了referer(“http://www.indianrail.gov.in/train_Schedule.html”)到你的代码,这似乎没有帮助。无法看到任何表格值错过...他们已经采取了保护措施,以阻止外部请求。我会建议找到一个不同的(更开放的)数据源。 – Ing 2012-03-14 10:47:50
@Ing明白了;请看下面。 – AgA 2012-03-14 11:04:01