2012-09-03 29 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