我为酒店创建了一个soap请求,但在测试时却一直出错。我是编码和编码的新手。 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;
?>
答案 0 :(得分:0)
如果这些是您希望使用的Sabre SOAP API,则需要将从SessionCreateRQ服务创建并返回的会话令牌作为SOAP标头的一部分传递。会话未在标头上传递。示例发布如下:
<?xml version="1.0" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 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">
<SOAP-ENV:Header>
<m:MessageHeader xmlns:m="http://www.ebxml.org/namespaces/messageHeader">
<m:From>
<m:PartyId type="urn:x12.org:IO5:01">99999</m:PartyId>
</m:From>
<m:To>
<m:PartyId type="urn:x12.org:IO5:01">123123</m:PartyId>
</m:To>
<m:CPAId>ABC</m:CPAId>
<m:ConversationId>abc123</m:ConversationId>
<m:Service m:type="OTA"/>
<m:Action>OTA_HotelAvailLLSRQ</m:Action>
<m:MessageData>
<m:MessageId>mid:20001209-133003-2333@clientofsabre.com</m:MessageId>
<m:Timestamp>2001-02-15T11:15:12Z</m:Timestamp>
<m:TimeToLive>2001-02-15T11:15:12Z</m:TimeToLive>
</m:MessageData>
<m:DuplicateElimination/>
<m:Description>Hotel Request</m:Description>
</m:MessageHeader>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext">
<wsse:BinarySecurityToken EncodingType="wsse:Base64Binary" valueType="String">Shared/IDL:IceSess\/SessMgr:1\.0.IDL/Common/!ICESMS\/RESF!ICESMSLB\/RES.LB!-3552340994681278428!1838077!0!1!E2E-1</wsse:BinarySecurityToken>
</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 NumProperties="50">
<Criterion>
<HotelRef HotelCityCode="DFW" HotelName="HYATT"/>
</Criterion>
</HotelSearchCriteria>
<TimeSpan End="06-28" Start="06-20"/>
</AvailRequestSegment>
</OTA_HotelAvailRQ>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>