2012-09-03 12 views
0

我想发布到使用PHP和cURL的网站,并获得搜索结果作为刮概念证明的一部分。但是,我的回应与我通过直接访问该网站所获得的回应并不相同。我已经使用FireBug捕获了所有的post参数和头文件,并使用cURL发送了所有这些参数和头文件,但响应仍然不相同。有人能帮助解决我可能做错了什么吗?PHP + cURL邮政不返回预期结果

我试图访问的网站是:http://book.goindigo.in/skylights/cgi-bin/skylights.cgi

在该网站上,我做了单向搜索将返回一串航班(例如,孟买,德里为9月25日)。我并不担心这个结果。显示航班后,如果选择了特定航班,则会在价格摘要部分的左侧显示票价分手。为了得到这个价格摘要,他们发射了一个ajax调用,这是我想用PHP和cURL来模拟的。

当通过站点访问时,ajax调用返回一堆javascript变量作为响应。但同样的调用返回页面的完整html,而不是通过cURL访问期望的JavaScript变量。

任何帮助,将不胜感激。

感谢

$url='https://book.goindigo.in/skylights/cgi-bin/skylights.cgi'; 

$header = array("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",  "Accept-Language: en-us,en;q=0.5", "Connection: keep-alive", "Cache-Control: no-cache", "Accept-Encoding: gzip,deflate", "Content-Length: 342", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Cookie: __utma=1.649498667.1346160326.1346395277.1346415046.4; __utmz=1.1346160326.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmb=1.11.10.1346415046; __utmc=1", "Host: book.goindigo.in", "Pragma: no-cache", "Referer: https://book.goindigo.in/skylights/cgi-bin/skylights.cgi"); 

$user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:15.0) Gecko/20100101 Firefox/15.0"; 

$referrer = 'https://book.goindigo.in/skylights/cgi-bin/skylights.cgi' ; 

$post_params="page=INCLUSIVE_PRICING&module=SB&sid=&adults=1&children=0&language=EN&infants=0&numberMarkets=1&market1Data=201209036E%20146BLRDEL%20ININERE0BLRDEL201209031345201209031630Regular%20Fare%20ADULT%20ADT%2001&market2Data=&flt1_cnx1_date=&flt1_cnx2_date=&flt1_paxType1_fare=440000&flt1_paxType2_fare=&itin_type=Domestic"; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, $header); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
#curl_setopt($ch, CURLOPT_PROXY, $proxy); 
#curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
curl_setopt($ch, CURLOPT_REFERER, $referer); 
curl_setopt($ch, CURLOPT_USERAGENT, $agent); 

$result = curl_exec($ch); 
$error = curl_error($ch); 

curl_close($ch); 

    echo $result; 
+0

也许API检查Referer。 – Barmar

+0

我试过通过referer,没有工作。我基本上复制了原始请求使用站点页面发送的整套标题和发布参数。 – Ramesh

+0

我刚刚使用Chrome开发人员工具捕获了帖子参数,并使用curl从命令行发送了它们,并获得了预期的javascript变量。你能发布你的PHP代码吗? – Barmar

回答

1

你丢失:

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params); 

这里就是我从壳做的:

curl -d "page=INCLUSIVE_PRICING&module=SB&sid=&adults=1&children=0&language=EN&infants=0&numberMarkets=2&market1Data=201209116E 176BOMDEL       ININERE0BOMDEL201209111325201209111530Regular Fare   ADULT ADT 01&market2Data=201209116E 175DELBOM       ININNRN0BOMDEL201209111345201209111555RoundTrip Fare   ADULT ADT 01&flt1_cnx1_date=&flt1_cnx2_date=&flt2_cnx1_date=&flt2_cnx2_date=&flt1_paxType1_fare=443000&flt1_paxType2_fare=&flt2_paxType1_fare=402000&flt2_paxType2_fare=&itin_type=Domestic" http://book.goindigo.in/skylights/cgi-bin/skylights.cgi 

产量为:

<!-- 
////////////////////////////////////////////////////////////////////////////// 
// Copyright(c) 2000 - 2006 Navitaire Inc. All rights reserved.   // 
//                   // 
// This source code is protected by copyright law and international  // 
// treaties. Unauthorized reproduction, distribution or alteration  // 
// of this source code, or any portion of it, may result in severe  // 
// civil and criminal penalties and will be prosecuted to the maximum // 
// extent possible under the law.          // 
//                   // 
// Skylights 9.4b-6E         www.navitaire.com // 
////////////////////////////////////////////////////////////////////////////// 
--> 

numRoutes=2; 
     r1destination=DEL; 
     r1origin=BOM; 

     r1fareLabel=Regular Fare   ; 


      r1Pax1Type=ADT; 

               r1Pax1DiscountBase= Rs 4,430.00 ; 
               r1Pax1TotalFareCost= Rs 8,426.00 ; 


                       r1Pax1Tax1Amount= Rs 233.00 INR; 


          r1Pax1Tax1SummedAmount=233.00; 


               r1Pax1Tax1Desciption=Passenger Service Fee; 







                       r1Pax1Tax2Amount= Rs 2,800.00 INR; 


          r1Pax1Tax2SummedAmount=2800.00; 


               r1Pax1Tax2Desciption=Fuel Surcharge; 







                       r1Pax1Tax3Amount= Rs 50.00 INR; 


          r1Pax1Tax3SummedAmount=50.00; 


               r1Pax1Tax3Desciption=Transaction Charge; 







                       r1Pax1Tax4Amount= Rs 360.00 INR; 


          r1Pax1Tax4SummedAmount=360.00; 


               r1Pax1Tax4Desciption=Service Tax; 








                       r1Pax1Tax6Amount= Rs 553.00 INR; 


          r1Pax1Tax6SummedAmount=553.00; 


               r1Pax1Tax6Desciption=User Development Fee; 






               r1Pax1TotalTaxAmount= Rs 3,996.00 ; 



          r1Pax1SummedFareAmount=4430.00; 



               r1Pax1SummedFareAmount=4430.00; 
               r1Pax1SummedTaxAmount= Rs 3,996.00 ; 



     r1InfDescription=; 
           r1InfDiscountBase= Rs 0.00 ; 
     r1InfSSRCode=; 
           r1InfTotalFareCost= Rs 0.00 ; 





           r1TotalInfTaxAmount= Rs 0.00 ; 
           r1RouteTotalTax= Rs 3,996.00 ; 
           r1RouteTotalAmount= Rs 8,426.00 ; 
           r1InfSummedFareAmount= Rs 0.00 ; 
           r1InfSummedTaxAmount= Rs 0.00; 
           r1SummedTaxAmount= Rs 3,996.00 ; 
           r1SummedAmount= Rs 8,426.00 ; 

     r2destination=BOM; 
     r2origin=DEL; 

     r2fareLabel=RoundTrip Fare   ; 


      r2Pax1Type=ADT; 

               r2Pax1DiscountBase= Rs 4,020.00 ; 
               r2Pax1TotalFareCost= Rs 8,101.00 ; 


                       r2Pax1Tax1Amount= Rs 146.00 INR; 


          r2Pax1Tax1SummedAmount=146.00; 


               r2Pax1Tax1Desciption=Passenger Service Fee; 







                       r2Pax1Tax2Amount= Rs 2,800.00 INR; 


          r2Pax1Tax2SummedAmount=2800.00; 


               r2Pax1Tax2Desciption=Fuel Surcharge; 







                       r2Pax1Tax3Amount= Rs 50.00 INR; 


          r2Pax1Tax3SummedAmount=50.00; 


               r2Pax1Tax3Desciption=Transaction Charge; 







                       r2Pax1Tax4Amount= Rs 340.00 INR; 


          r2Pax1Tax4SummedAmount=340.00; 


               r2Pax1Tax4Desciption=Service Tax; 








                       r2Pax1Tax6Amount= Rs 745.00 INR; 


          r2Pax1Tax6SummedAmount=745.00; 


               r2Pax1Tax6Desciption=User Development Fee; 






               r2Pax1TotalTaxAmount= Rs 4,081.00 ; 



          r2Pax1SummedFareAmount=4020.00; 



               r2Pax1SummedFareAmount=4020.00; 
               r2Pax1SummedTaxAmount= Rs 4,081.00 ; 



     r2InfDescription=; 
           r2InfDiscountBase= Rs 0.00 ; 
     r2InfSSRCode=; 
           r2InfTotalFareCost= Rs 0.00 ; 





           r2TotalInfTaxAmount= Rs 0.00 ; 
           r2RouteTotalTax= Rs 4,081.00 ; 
           r2RouteTotalAmount= Rs 8,101.00 ; 
           r2InfSummedFareAmount= Rs 0.00 ; 
           r2InfSummedTaxAmount= Rs 0.00; 
           r2SummedTaxAmount= Rs 4,081.00 ; 
           r2SummedAmount= Rs 8,101.00 ; 

       TransactionFeeAmount=0.00; 
       TotalPackageAmount=Rs 16,527.00 ; 
       PrefixType=Rs ; 
+0

对不起,这只是一个错字。我也有过参数。无论如何,我试着用post_params,但结果仍然是一样的。如果您不介意,您可以发布您使用的确切代码吗?我可能错过了一些非常简单的东西,我无法弄清楚。感谢您的帮助。 – Ramesh

+0

用我运行的shell命令编辑我的答案。 – Barmar

+0

我终于搞定了。问题在于后面的参数中有一些空格,我认为这些空格并不是必需的,并已将它们改为单个空格。一旦我将准确的后参数复制到空格的确切数量后,它就开始工作。感谢Barmar帮忙。 – Ramesh