У меня есть следующие коды, однако он ничего не возвращает - пустую страницу. Но если я подключу нужные параметры и поместил всю ссылку в веб-браузере, это вернет результаты, которые я хочу. Я не хочу использовать file_get_contents, потому что мне нужно использовать эту функцию для других вызовов API, которые не могут возвращать результаты, введя всю ссылку в адресной строке. Спасибо за помощь.Использовать cURL для вызова API в PHP
<?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¤cyCode=USD&xml=');
// This section sets various options. See http://www.php.net/manual/en/function.curl-setopt.php
curl_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 handle
curl_close ($curl_handle);
echo $result;
?>
Проверка ошибок curl - exec() возвращает boolean FALSE при сбое: 'if ($ result === false) {curl_error ($ curl_handle); } ' –