0
我不知道是否有人可以幫我解決這個問題 - 我一直在嘗試幾個小時,沒有快樂。提交時,我收到一條錯誤消息,指出「使用POST方法發送XML參數」。我以爲我正在這樣做,但顯然不是。任何指針都非常感謝。顯然,用戶名,密碼和網址都在現場版本不同使用Post方法發送XML參數
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);
感謝您的回覆Sabuj。我已經嘗試過了,並且還使用了'text/xml'和'application/x-www-form-urlencoded',但是我仍然得到相同的錯誤 – Dean
你可以添加'curl_setopt($ ch,CURLOPT_VERBOSE,1);' 。它將生成curl的調試打印並使用它可以進一步追蹤。 –
謝謝Sabuj。我會放棄這一點 – Dean