当我在代码下面运行时,我得到了响应500内部服务器错误,我认为代码是完美的,所以有人可以帮我这个吗?
<?php
$xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$xml .= '<CountryListRQ echoToken="DummyEchoToken" xmlns="http://www.hotelbeds.com/schemas/2005/06/messages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.hotelbeds.com/schemas/2005/06/messages CountryListRQ.xsd">';
$xml .= '<Language>ENG</Language>';
$xml .= '<Credentials>';
$xml .= '<User>username</User>';
$xml .= '<Password>password</Password>';
$xml .= '</Credentials>';
$xml .= '</CountryListRQ>';
$url = 'http://212.170.239.71/appservices/ws/FrontendService?wsdl';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml; charset=utf-8; action="getCountryList"'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('xml' => $xml));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$result = @curl_exec($ch);
echo "<pre>";
print_r($result);
exit;
if($result === false) {
echo "Error performing request";
} else {
$xml_doc = simplexml_load_string($result);
echo 'status is ', $xml_doc->status, '<br/>';
if ($xml_doc->status == 'SUCCESS') {
print_r($result);
} else {
echo 'Error is ', $xml_doc->errormessage, '<br/>';
}
}?>
我得到了这样的回应,
HTTP/1.1 100 Continue
HTTP/1.1 500 Internal Server Error
Date: Sat, 02 Feb 2013 06:02:12 GMT
Server: Resin/2.1.17
Content-Type: text/xml; charset=utf-8
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked
soapenv:Server.userExceptionorg.xml.sax.SAXParseException: Content is not allowed in prolog.we3mpf01
任何人都可以帮助我吗?如何使用这个hotelbed api获取国家/地区列表?
答案 0 :(得分:2)
使用以下http服务网址:
http://212.170.239.71/appservices/http/AcceptanceTest
我在hotelbeds服务器停机的时候,这就是发生这种错误的原因。
答案 1 :(得分:1)
错误消息告诉您缺少SOAP包装器元素,即&lt; soap:Envelope&gt;,&lt; soap:Body&gt;等 - 请参阅基本用法示例:
http://www.soapuser.com/basics3.html
然而,我不建议使用curl(这是一个低级HTTP工具)与服务器进行交互,而是建议检查SOAP包:
http://php.net/manual/en/book.soap.php
这将为您完成所有包装并为您提供一个很好的OO层。
如果您出于某种原因故意学习SOAP的低级细节,那么至少您示例中的XML需要位于&lt; soap:Envelope&gt;内。和&lt; soap:Body&gt;,而不仅仅是单独出来。