簡體   English   中英

PHP Soap Request:請求中缺少XML正文

[英]PHP Soap Request: XML Body missing in the request

要求XML

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://schemas.navitaire.com/WebServices/ISessionManager/Logon</Action>
<h:ContractVersion xmlns:h="http://schemas.navitaire.com/WebServices">330</h:ContractVersion>
</s:Header>
<s:Body>
<LogonRequest xmlns="http://schemas.navitaire.com/WebServices/ServiceContracts/SessionService">
  <logonRequestData xmlns:d4p1="http://schemas.navitaire.com/WebServices/DataContracts/Session" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <d4p1:DomainCode>WWW</d4p1:DomainCode>
    <d4p1:AgentName>API****</d4p1:AgentName>
    <d4p1:Password>********</d4p1:Password>
    <d4p1:LocationCode i:nil="true" />
    <d4p1:RoleCode>APIB</d4p1:RoleCode>
    <d4p1:TerminalInfo i:nil="true" />
  </logonRequestData>
</LogonRequest>
</s:Body>
</s:Envelope>

WSDL包含http://pastie.org/9263788

PHP代碼

$options  = array("soap_version"=> SOAP_1_1,
            "trace"=>1,
            "exceptions"=>0
            );

$client = new SoapClient('https://trtestr3xapi.navitaire.com/sessionmanager.svc?wsdl',$options);

$header[] = new SoapHeader('http://schemas.microsoft.com/ws/2005/05/addressing/none','Action','http://schemas.navitaire.com/WebServices/ISessionManager/Logon',1);
$header[] = new SoapHeader('http://schemas.navitaire.com/WebServices','ContractVersion','330', false);

$client->__setSoapHeaders($header);

$params = array("LogonRequestData" => array("AgentName" => "API*****",
                "Password" => "Pass****",
                "RoleCode" => "APIB",
                "DomainCode" => "WWW"));

try{   
$h= $client->Logon($params); 
print nl2br(print_r($h, true));  
echo 'Request : <br/><xmp>', 
$client->__getLastRequest();
echo '</xmp>';
}
catch(SoapFault $fault){  
echo 'Request : <br/><xmp>', 
$client->__getLastRequest(), 
'</xmp><br/><br/> Error Message : <br/>', 
$fault->getMessage(); 
} 

從__getLastRequest()生成的XML請求

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.navitaire.com/WebServices/ServiceContracts/SessionService" xmlns:ns2="http://schemas.microsoft.com/ws/2005/05/addressing/none" xmlns:ns3="http://schemas.navitaire.com/WebServices">
<SOAP-ENV:Header>
    <ns2:Action SOAP-ENV:mustUnderstand="1">http://schemas.navitaire.com/WebServices/ISessionManager/Logon</ns2:Action>
    <ns3:ContractVersion>330</ns3:ContractVersion>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
    <ns1:LogonRequest/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

如您所見,XML主體為空。 如何用參數填充身體?

可以在此處看到完整的輸出,該輸出位於try{ }塊中http://pastie.org/9295467

在輸出中,您還可以看到

//If i use soap version 1.1
[faultstring] => Bad Request  
[faultcode] => HTTP

//If i use soap version 1.2
[faultstring] => Cannot process the message because the content type 'application/soap+xml; charset=utf-8; action="http://schemas.navitaire.com/WebServices/ISessionManager/Logon"' was not the expected type 'text/xml; charset=utf-8'.
[faultcode] => HTTP

您是否嘗試過切換到SOAP_1_2,因為該錯誤消息看起來像與此相關。 否則,你可以使用WSDL的PHP發電機如WsdlToPhpwsdltophp.com

我遇到了同樣的問題,並設法使用SOAP_1_1對其進行了修復而不進行壓縮。

因此,只需禁用壓縮即可。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM