File_Get_Contents - Failed to Open Stream: Http Request Failed! Http/1.1 404 Not Found

file_get_contents - failed to open stream: HTTP request failed

The problem is that your url is read literally due to '.

If you use " then the variables in the string will be used as variables but now your string is '...apikey=$api' instead of '...apikey=sdflsdksdksdsdskd'

So change the line

$json_url = file_get_contents('https://api.sandbox.amadeus.com/v1.2/flights/low-fare-search?origin=$origin&destination=$destination&departure_date=$departure_date&return_date=$return_date&number_of_results=$number_of_results&apikey=$apikey');

To

$json_url = file_get_contents("https://api.sandbox.amadeus.com/v1.2/flights/low-fare-search?origin=$origin&destination=$destination&departure_date=$departure_date&return_date=$return_date&number_of_results=$number_of_results&apikey=$apikey");

file_get_contents failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in

file_get_contents (read the tip on blue rectangle) can be easily blocked on server side through php.ini avoid using it. When you want to get data from an other site use curl instead. http://php.net/manual/en/book.curl.php, there are plenty of options that you can use with curl, by playing a bit the following code can work with your url.

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_URL,"https://cgi.ebay.com/ws/eBayISAPI.dll?ViewItemRevisionDetails&item=272908801183");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13");
$data = curl_exec($ch);
curl_close($ch);

and by echoing the $data varible you can see the whole page.

echo $data;

you can try parsing the data from the page by utilizing php DOM Methods and convert them to the data type you want (object class, array etc).



Related Topics



Leave a reply



Submit