我正在使用CURL发送API请求,但无法获取请求。当您直接在浏览器中调用API时,它可以正常工作。
这是链接
http://api.ean.com/ean-services/rs/hotel/v3/info?cid=55505&minorRev=99&apiKey=5d9cp7nfxruc7p788fvvqpwn&locale=en_US¤cyCode=USD&hotelId=123912
这是我的 CURL 代码:
$post_string1 = "cid=55505&minorRev=99&apiKey=5d9cp7nfxruc7p788fvvqpwn&locale=en_US¤cyCode=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);
我收到了http 405错误代码。请指导我做错了什么。
$post_string1
中删除URL,它只应包含POST参数。$post_string1 = 'cid=55505&minorRev=99&apiKey=5d9cp7nfxruc7p788fvvqpwn&locale=en_US¤cyCode=USD&type=xml&hotelId=123912';
- Fracsi