我为酒店创建了一个肥皂请求,但在测试时不断出错。我是编码和 stackoverflow 的新手,所以如果我遗漏了什么,请突出显示。
这是我的php代码后面的错误;
<soap-env:Envelope><soap-env:Header/><soap-env:Body><soap-env:Fault><faultcode>soap-env:Client.InvalidEbXmlMessage</faultcode><faultstring>Unable to create envelope from given source: Error on line -1 of document : Premature end of file. Nested exception: Premature end of file.</faultstring><detail><StackTrace>javax.xml.soap.SOAPException: Unable to create envelope from given source: Error on line -1 of document : Premature end of file. Nested exception: Premature end of file.</StackTrace></detail></soap-env:Fault></soap-env:Body></soap-env:Envelope>
我正在使用的代码:
<?php
//sws-crt.cert.sabre.com // https://sws3-sts.cert.sabre.com
//Data, connection, auth
$soapUrl = "https://sws-crt.cert.sabre.com"; // asmx URL of WSDL
//?op=OTA_HotelAvail
// xml post structure
$xml_post_string = '<SOAP-ENV:Envelope xmlns:SOAP- ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<wsse:Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" env:mustUnderstand="1">
<wsse:UsernameToken xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>xxx</wsse:Username>
<wsse:Password>xxx</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<OTA_HotelAvailRQ Version="2.1.0" xmlns="http://webservices.sabre.com/sabreXML/2011/10" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<AvailRequestSegment>
<Customer>
<Corporate>
<ID>ABC123</ID>
</Corporate>
</Customer>
<GuestCounts Count="2"/>
<HotelSearchCriteria>
<Criterion>
<HotelRef HotelCityCode="HNL"/>
</Criterion>
</HotelSearchCriteria>
<TimeSpan End="06-28" Start="06-20"/>
</AvailRequestSegment>
</OTA_HotelAvailRQ>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>'; // data from the form, e.g. some ID number
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Authorization: Bearer Shared/IDL:IceSess\/SessMgr:1\.0.IDL/Common/!ICESMS\/ACPCRTD!ICESMSLB\/CRT.LB!-3547302473499669854!495515!0!!E2E-1 X-Originating-Ip: xxxxxx ",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: OTA_HotelAvailLLSRQ",
"Content-length: " . strlen($xml_post_string)
); //SOAPAction: your op URL
$url = $soapUrl;
// PHP cURL for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_USERPWD, "powderwhite:B=Antika789"); // username and password - declared at the top of the doc
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
header('Content-type: text/xml');
// converting
$response = curl_exec($ch);
curl_close($ch);
//echo "<pre>";
print_r($response);
// converting
/// $response1 = str_replace("<soap:Body>","",$response);
// $response2 = str_replace("</soap:Body>","",$response1);
// convertingc to XML
// $parser = simplexml_load_string($response2);
// user $parser to get your data out of XML response and to display it.
//echo $parser;
?>