我想知道是否有人可以帮我解决这个问题 - 我已经尝试了几个小时但没有快乐。提交时,我收到一条错误消息,说明"使用POST方法发送XML参数"。我以为我这样做但显然没有。任何指针都非常感谢。显然,实时版本的用户名,密码和URL是不同的
define('XML_PAYLOAD', '<?xml version=\"1.0\" encoding=\"UTF-8\"?><Request><Head><Username>myusername</Username><Password>mypassword</Password><RequestType>HotelSearch</RequestType></Head><Body><HotelIds><HotelId>2234836</HotelId></HotelIds><CheckInDate>2017-05-01</CheckInDate><CheckOutDate>2017-05-08</CheckOutDate><Rooms><Room><NumAdults>2</NumAdults></Room></Rooms><Nationality>GB</Nationality><Currency>GBP</Currency><AvailableOnly>0</AvailableOnly></Body></Request>');
define('XML_POST_URL', 'http://theurl');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, XML_POST_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_POSTFIELDS, XML_PAYLOAD);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));
$start = array_sum(explode(' ', microtime()));
$result = curl_exec($ch);
$stop = array_sum(explode(' ', microtime()));
$totalTime = $stop - $start;
if ( curl_errno($ch) ) {
$result = 'ERROR -> ' . curl_errno($ch) . ': ' . curl_error($ch);
} else {
$returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
switch($returnCode){
case 404:
$result = 'ERROR -> 404 Not Found';
break;
default:
break;
}
}
curl_close($ch);
echo 'Total time for request: ' . $totalTime . "\n";
echo $result;
exit(0);
答案 0 :(得分:0)
使用您的请求标头添加内容类型:
text/xml
或者可能是{{1}}或服务器正在接受的任何内容。