php - curl getting header and cookie from one URL and posting to another URL to retrieve data -
i'm trying retrieve json data url, requires http authorization (no password) cookie , header data need parent url.
i've managed retrieve header information integrating within post part of script having difficulty with.
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"; // want post data curl_setopt($ch2, curlopt_url, $url2); curl_setopt($ch2, curlopt_post, true); // tell curl want post 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 want post curl_setopt($ch2, curlopt_returntransfer, true); // return output in string format $output = curl_exec ($ch2); // execute var_dump($output); // show output
Comments
Post a Comment