我遇到过有趣的事件。我使用curl发送soap请求,但是我得到的错误如下。但是当我在SoapUI上尝试相同的请求时,我得到了成功的响应,所以我无法理解为什么我会在php curl上出错。
错误:
soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header />
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Client</faultcode>
<faultstring>java.lang.RuntimeException: Unexpected subelement Envelope</faultstring>
<detail />
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
请求:
<s:Envelope xmlns:s = "http://schemas.xmlsoap.org/soap/envelope/">
<Header xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<UsernameToken>
<Username>MARMARAXML</Username>
<Password>12345</Password>
</UsernameToken>
</Security>
</Header>
<s:Body xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
<OTA_AirAvailRQ xmlns="http://otabase.otapax.otaxmlws/">
<POS xmlns="http://ota.paxws.otaxmlws/">
<Source xmlns="http://types.paxws.otaxmlws/" isoCountry="NL" isoCurrency="EUR">
<RequestorID/>
<BookingChannel/>
</Source>
</POS>
<OriginDestinationInformation xmlns="http://ota.paxws.otaxmlws/">
<DepartureDateTime xmlns="http://types.paxws.otaxmlws/">2015-03-07</DepartureDateTime>
<OriginLocation xmlns="http://types.paxws.otaxmlws/" LocationCode="AMS"/>
<DestinationLocation xmlns="http://types.paxws.otaxmlws/" LocationCode="IST"/>
</OriginDestinationInformation>
<TravelPreferences xmlns="http://ota.paxws.otaxmlws/">
<FlightTypePref xmlns="http://types.paxws.otaxmlws/"/>
<EquipPref xmlns="http://types.paxws.otaxmlws/"/>
<CabinPref xmlns="http://types.paxws.otaxmlws/"/>
<TicketDistribPref xmlns="http://types.paxws.otaxmlws/"/>
<BookingClassPref xmlns="http://types.paxws.otaxmlws/"/>
</TravelPreferences>
<TravelerInfoSummary xmlns="http://ota.paxws.otaxmlws/">
<AirTravelerAvail xmlns="http://types.paxws.otaxmlws/">
<PassengerTypeQuantity Code="ADT" Quantity="1"/>
<temp>String</temp>
</AirTravelerAvail>
</TravelerInfoSummary>
</OTA_AirAvailRQ>
</s:Body>
</s:Envelope>
PHP代码
$soap_do = curl_init($account[OnurAccount::ENDPOINT]);
$header = array(
"Content-Type: text/xml;charset=UTF-8",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction:/".$soapAction,
"Content-length: " . strlen($message),
);
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 30);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true);
//curl_setopt($soap_do, CURLOPT_SSLVERSION, CURL_SSLVERSION_DEFAULT);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true);
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $message);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
$result_xml = curl_exec($soap_do);
Wsdl地址:http://onur-stage.crane.aero/axis2/services/CraneOTAService?wsdl
谢谢,
答案 0 :(得分:0)
嗨,我知道这是愚蠢的,但我发现SOAP请求有一个&#34;空间&#34;在信封开始元素之前。删除它,然后重试。
答案 1 :(得分:0)
使用跟随curl
命令,我使用您在问题中发布的请求成功调用您的网络服务:
curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:/Availability" --data @request.xml http://onur-stage.crane.aero:80/axis2/services/CraneOTAService
其中:
--header "Content-Type: text/xml;charset=UTF-8"
为典型的SOAP请求添加正确的Content-type
http-header
。
--header "SOAPAction:/Availability"
包含WS所需的http-header
SOAPAction。
--data @request.xml
指向您的请求,我将其保存在执行命令的同一路径内的request.xml
文件中。
我收到了以下回复(我认为这是预期的)。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header />
<soapenv:Body>
<ns2:OTA_AirAvailRSType xmlns:ns2="http://ota.paxws.otaxmlws/" SequenceNmbr="1" TimeStamp="2015-03-06 13:29:06.166">
<Success xmlns="http://ota.paxws.otaxmlws/">true</Success>
<OriginDestinationOptions xmlns="http://ota.paxws.otaxmlws/">
<OriginDestinationOption xmlns="http://types.paxws.otaxmlws/">
<FlightSegment ArrivalDateTime="2015-03-07 19:25:00.0" DepartureDateTime="2015-03-07 14:55:00.0" FlightNumber="372" JourneyDuration="" OnTimeRate="" RPH="" ResBookDesigCode="" ResBookDesigID="" Status="" StopQuantity="0" Ticket="">
<DepartureAirport LocationCode="AMS" />
<ArrivalAirport LocationCode="IST" />
<Equipment AirEquipType="A320-232 / 180Y" ChangeofGauge="NONE" />
<MarkettingAirline CompanyShortName="8Q" />
<MarketingCabin CabinType="" RPH="0">
<Meal>*</Meal>
</MarketingCabin>
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="A" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="D" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="Y" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="Q" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="B" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="L" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="M" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="H" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="K" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="N" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="S" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="I" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="V" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="W" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="T" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="U" ResBookDesigQuantity="9" />
<BookingClassAvail CabinType="" RPH="0" ResBookDesigCode="P" ResBookDesigQuantity="9" />
<comment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
</FlightSegment>
<dummy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
</OriginDestinationOption>
<dummy xmlns="http://types.paxws.otaxmlws/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
</OriginDestinationOptions>
</ns2:OTA_AirAvailRSType>
</soapenv:Body>
</soapenv:Envelope>
希望这有帮助,