PHP curl Soap 请求错误
PHP curl Soap Request Error
我遇到了一个有趣的事件。我使用 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
谢谢,
您好,我知道这很愚蠢,但我看到 SOAP 请求在信封开始元素之前有一个 "space"。删除它并重试。
使用以下 curl
命令,我使用您 post 在您的问题中提出的请求成功调用了您的网络服务:
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>
希望这对您有所帮助,
我遇到了一个有趣的事件。我使用 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
谢谢,
您好,我知道这很愚蠢,但我看到 SOAP 请求在信封开始元素之前有一个 "space"。删除它并重试。
使用以下 curl
命令,我使用您 post 在您的问题中提出的请求成功调用了您的网络服务:
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>
希望这对您有所帮助,