954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

passing xml in api and get data in xml with help of curl

http://api.ean.com/ean-services/rs/hotel/v3/list?minorRev=4&cid=55505&apiKey=5q4gzx43g6ukcrq798z2hz75&customerSessionId=&locale=en_US&currencyCode=USD&xml=new%20delhi2

when i call api directly to browser i got right data in xml format.


but when i call it through curl.. sometime i get data in json format or sometimes no data..

$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;


help me.

thanks in advance

sam230
Light Poster
25 posts since Jul 2011
Reputation Points: 10
Solved Threads: 2
 

try to set the CURLOPT_HTTPHEADER something like this:
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") );

ddymacek
Posting Whiz
317 posts since Jun 2010
Reputation Points: 36
Solved Threads: 64
 

does not change anything.. the api above works.. so you can test it and try to call it from curl.. try some changes in code.. if it works thn reply.. thanks

sam230
Light Poster
25 posts since Jul 2011
Reputation Points: 10
Solved Threads: 2
 

no help..??? :O

sam230
Light Poster
25 posts since Jul 2011
Reputation Points: 10
Solved Threads: 2
 

Here ya go...
you need to add an _type variable to your request.
right after currency code and before xml=...
add &_type=xml so:
...&locale=en_US&currencyCode=USD&_type=xml&xml=

ddymacek
Posting Whiz
317 posts since Jun 2010
Reputation Points: 36
Solved Threads: 64
 

thanks for the reply.. yeah that the problem.. :)

sam230
Light Poster
25 posts since Jul 2011
Reputation Points: 10
Solved Threads: 2
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: