我想發佈到使用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;
也許API檢查Referer。 – Barmar
我試過通過referer,沒有工作。我基本上覆制了原始請求使用站點頁面發送的整套標題和發佈參數。 – Ramesh
我剛剛使用Chrome開發人員工具捕獲了帖子參數,並使用curl從命令行發送了它們,並獲得了預期的javascript變量。你能發佈你的PHP代碼嗎? – Barmar