user375947
user375947

Reputation: 115

Problem fetching XML data using Expedia API and curl

When I load the URL used below in curl function directly in a browser, I get correct data in XML format.

But when I call it through curl, sometimes I get data in JSON format or sometimes no dat at all.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://api.ean.com/ean-services/rs/hotel/v3/list?minorRev=4&cid=55505&apiKey=5q4gzx43g6ukcrq798z2hz75&customerSessionId=&locale=en_US&currencyCode=USD&xml=<HotelListRequest><city>new%20delhi</city><RoomGroup><Room><numberOfAdults>2</numberOfAdults><numberOfResults></numberOfResults></Room></RoomGroup></HotelListRequest>");
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$retValue = curl_exec($ch);                     
curl_close($ch);

echo $retValue;

The above API is working so you can test it yourself.

Upvotes: 1

Views: 1794

Answers (1)

Grzegorz Szpetkowski
Grzegorz Szpetkowski

Reputation: 37944

You need to specify XML content type explicitly in your HTTP request by setting Accept header field, so REST server knows what do you want e.g.:

Accept: text/xml,application/xml;q=1

In your case (q=1 is default value):

curl_setopt($ch,CURLOPT_HTTPHEADER,array('Accept: text/xml,application/xml'));

Upvotes: 2

Related Questions