1
我試圖用SoapClient的調用的API,但認證PHP純XML失敗,因爲命名空間中的XML失蹤在SOAP
除外XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://tourico.com/webservices/" xmlns:trav="http://tourico.com/travelservices/">
<soapenv:Header>
<web:LoginHeader>
<trav:username>*****</trav:username>
<trav:password>*******</trav:password>
<trav:culture>en_US</trav:culture>
<trav:version>7.123</trav:version>
</web:LoginHeader>
</soapenv:Header>
<soapenv:Body>
<web:CancelReservation>
<web:nResID>1235456</web:nResID>
</web:CancelReservation>
</soapenv:Body>
</soapenv:Envelope>
我所actualy在發送(沒有命名空間LoginHeader)
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tourico.com/webservices/" xmlns:ns2="http://tourico.com/travelservices/">
<SOAP-ENV:Header>
<ns2:LoginHeader>
<username>******</username>
<password>*******</password>
<culture>en_US</culture>
<version>8.0</version>
</ns2:LoginHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:CancelReservation>
<ns1:nResID>95665639</ns1:nResID>
</ns1:CancelReservation>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我的PHP代碼
$url = "http://demo-wsnew.touricoholidays.com/ReservationsService.asmx?wsdl";
$user = "*****";
$pwd = "********";
$culture = "en_US";
$version = "8.0";
$wsdl = $url;
$client = new SOAPClient($wsdl,array("trace" => true, "exceptions" => true, 'soap_version' => SOAP_1_1));
$login = new stdClass();
$login->usernam= $user;
$login->password = $pwd;
$login->culture = $culture;
$login->version = $version;
// Turn auth header into a SOAP Header
$header = new SoapHeader('http://tourico.com/travelservices', 'LoginHeader', $login, false);
// set the header
$client->__setSoapHeaders($header);
$r = new stdClass();
$r->nResID = 123456;
try
{
$res = $client->CancelReservation($r);
$results = json_decode(json_encode($res), true);
Log::error($client->__getLastRequest());
Log::error(print_r($results , true));
}
catch(Exception $e)
{
Log::error($client->__getLastRequest());
Log::error($e->getMessage());
}
有沒有一種方法可以將XML字符串發送到SOAPclient?