卷曲从一个URL获取标题和cookie并发布到另一个URL以检索数据

时间:2014-04-14 12:38:51

标签: php cookies curl

我正在尝试从URL中检索json数据,但是它需要http授权(无密码),只需要从父URL获取cookie和头数据。

我成功地检索了标题信息,但是将其集成在我遇到问题的脚本的后期部分中。

function check_link($link) {
$main = array();
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $link);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_NOBODY, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_NETRC, 1); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 300);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT    5.0)");

ob_start();
   curl_exec ($ch);
   $stuff = ob_get_contents();
ob_end_clean();

curl_close ($ch);

return $stuff;

}

$link = 'http://www.avis.fr/default.aspx'; //parent URL
$returnData = check_link($link);
print_r($returnData); //HEADER INFORMATION

curl_setopt($ch2, CURLOPT_HTTPHEADER, array ($returnData)); 
$url2 = "http://www.avis.fr/WebServices/LocationSearch.asmx/GetStations"; // where I     want to post data
curl_setopt($ch2, CURLOPT_URL, $url2);
curl_setopt($ch2, CURLOPT_POST, true);  // tell curl you want to post something
curl_setopt($ch2, CURLOPT_POSTFIELDS, "searchTerm=ares&countryId=56&pickUpDate=2014-04-    15 09:00&dropOffDate=2014-04-17 09:00&isPickup=true&returnToSameLocation=true"); // define     what you want to post
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true); // return the output in string format
$output = curl_exec ($ch2); // execute

var_dump($output); // show output

0 个答案:

没有答案