您好,任何愿意帮助的人.. 我不知道还能做什么。我正在尝试向 api 发送一个 xml 请求,它将返回一个 xml 格式的响应。我正在使用 curl 来实现它。但无论我以何种方式格式化我的请求,我总是得到 400 响应。url 格式正确。这是我的代码:
$ch1 = curl_init();
$fp1 = fopen('poi.xml','w');
curl_setopt($ch1, CURLOPT_URL, "http://api.ean.com/ean-services/rs/hotel/v3/geoSearch?cid=55505&minorRev=14&apiKey=xkr94zxbsjnzczryqajmjg3g&locale=en_US¤cyCode=USD&customerIpAddress=189.214.86.135&customerUserAgent=Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31&xml=<LocationInfoRequest><destinationString>Dallas, TX</destinationString><type>2</type></LocationInfoRequest>");
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);
curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch1, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
$val1 = curl_exec($ch1);
$info = curl_getinfo($ch1);
echo '<pre>';
print_r($info);
echo '</pre>';
curl_close($ch1);//Close curl session
fclose($fp1); //Close file overwrite
$avail = simplexml_load_file('poi.xml');
这是我从 curl 获得的信息:
[url] => http://api.ean.com/ean-services/rs/hotel/v3/geoSearch?cid=55505&minorRev=14&apiKey=xkr94zxbsjnzczryqajmjg3g&locale=en_US¤cyCode=USD&customerIpAddress=189.214.86.135&customerUserAgent=Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31&xml=Dallas, TX2
[content_type] => text/html
[http_code] => 400
[header_size] => 158
[request_size] => 558
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.075402
[namelookup_time] => 0.038232
[connect_time] => 0.055687
[pretransfer_time] => 0.055787
[size_upload] => 0
[size_download] => 349
[speed_download] => 4628
[speed_upload] => 0
[download_content_length] => 349
[upload_content_length] => 0
[starttransfer_time] => 0.07531
[redirect_time] => 0
我究竟做错了什么?任何帮助,将不胜感激。