4

I am sending request to API using CURL, but not able to get request. The API works well when you call it directly in browser.

Here is the link

http://api.ean.com/ean-services/rs/hotel/v3/info?cid=55505&minorRev=99&apiKey=5d9cp7nfxruc7p788fvvqpwn&locale=en_US&currencyCode=USD&hotelId=123912

my CURL code is here

  $post_string1 = "cid=55505&minorRev=99&apiKey=5d9cp7nfxruc7p788fvvqpwn&locale=en_US&currencyCode=USD&type=xml&hotelId=123912";  

  $path1 = "http://api.ean.com/ean-services/rs/hotel/v3/info"; //Relative path to the file with $_POST parsing

$ch1 = curl_init($path1); 
$fp1 = fopen('hotel.xml','w');
curl_setopt($ch1, CURLOPT_POSTFIELDS, $post_string1); //Send the data to the file
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_HTTPHEADER, array('Accept: application/xml')); 
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch1, CURLOPT_FILE, $fp1);
$val = curl_exec($ch1);
$info = curl_getinfo($ch1);
curl_close($ch1);//Close curl session
fclose($fp1); //Close file overwrite

//$hotel = simplexml_load_file('hotel.xml');

echo '<pre>';print_r($info); 

I get http 405 code. Please advice what i am doing wrong.

7
  • 403 forbidden: your credentials aren't valid. As simple as that. Commented Oct 2, 2013 at 10:23
  • Remove url from $post_string1, it only should contain the post params. $post_string1 = 'cid=55505&minorRev=99&apiKey=5d9cp7nfxruc7p788fvvqpwn&locale=en_US&currencyCode=USD&type=xml&hotelId=123912'; Commented Oct 2, 2013 at 10:24
  • sorry but i modified my question. Its 405 code. wrong typo :) Commented Oct 2, 2013 at 10:24
  • 2
    405 Method Not Allowed: you can't use POST when the server was expecting a GET (or vice-versa) Commented Oct 2, 2013 at 10:25
  • 1
    yes, but we want to know WHY shazad's code does not work and yours do. We're not just looking for code, but for knowledge! Commented Oct 2, 2013 at 10:28

1 Answer 1

6

Check this

$post_string1 = "http://api.ean.com/ean-services/rs/hotel/v3/info?cid=55505&minorRev=99&apiKey=5d9cp7nfxruc7p788fvvqpwn&locale=en_US&currencyCode=USD&type=xml&hotelId=123912";  
$header[] = "Accept: application/json";
  $header[] = "Accept-Encoding: gzip";
  $ch = curl_init();
  curl_setopt( $ch, CURLOPT_HTTPHEADER, $header );
  curl_setopt($ch,CURLOPT_ENCODING , "gzip");
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  curl_setopt( $ch, CURLOPT_URL, $post_string1 );
  curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  $response = json_decode(curl_exec($ch));
  print_r($response);  exit;
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks srivi. I think POST method is not allowed in this api. Can i use this code in loop to get data for multiple hotels?
if you want multi hotel result use api.ean.com/ean-services/rs/hotel/v3/list?minorRev=14. Please read this documentation developer.ean.com. Its contain all your need with examples
By multiple i meant, keep requesting with different hotel Id's in foreach or for loop. Possible?
@M Shahzad Khan Ya sure
@NathanSrivi you shouldn't fish so hard for points. It's a bad practice to accept an answer within the first 24hrs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.