Use cURL to call API in PHP

getryuiqq

New Member
I have the following codes, however, it does not return anything-a blank page. But if I plug in the right parameters and place the entire link on web browser, it would return the results I want. I don't want to use file_get_contents because I need to use this function for other API calls that cannot return results by entering the entire link on the address bar. Thanks for helping.\[code\]<?php$data_string ='<HotelListRequest><hotelId>A HOTEL</hotelId></HotelListRequest>';// Tell CURL the URL of the recipient script$curl_handle = curl_init ();curl_setopt ($curl_handle, CURLOPT_URL, 'http://api.ean.com/ean-services/rs/hotel/v3/info?minorRev=4&cid=MYID&apiKey=MYAPIKEY&customerSessionId=&locale=en_US&currencyCode=USD&xml=');// This section sets various options. See http://www.php.net/manual/en/function.curl-setopt.phpcurl_setopt ($curl_handle, CURLOPT_FOLLOWLOCATION, 1);curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, true);curl_setopt ($curl_handle, CURLOPT_POST, true);curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data_string);// Perform the POST and get the data returned by the server.$result = curl_exec ($curl_handle);// Close the CURL handlecurl_close ($curl_handle);echo $result; ?>\[/code\]
 
Back
Top