问题
I am trying to send authentication header in SOAP but it's not working and keep showing error like 'Invalid authentication info'.
$options=array(
'senderCity'=>'Atlanta',
'senderState'=>'GA',
'senderZip'=>'30005',
'senderCountryCode'=>'USA',
'receiverCity'=>'Atlanta',
'receiverState'=>'GA',
'receiverZip'=>'30005',
'receiverCountryCode'=>'USA'
);
$headerbody = array(
'loginId'=>'xxxxxxxx',
'password'=>'xxxxxxxx',
'licenseKey'=>'xxxxxxxxxxxxx',
'accountNumber'=>'xxxxxxxxxx');
$soap_client = new SoapClient('http://www.wwexship.com/webServices/services/SpeedFreightShipment?wsdl');
$header = new SoapHeader('http://www.wwexship.com/webServices/', 'AuthenticationToken', $headerbody, false);
$soap_client->__setSoapHeaders(array($header));
$result = $soap_client->__call('quoteSpeedFreightShipment',$options);
echo "<pre>";
print_r($result);
echo "<pre>";
Can any one help me to resolve this.
Thank you
回答1:
Correcting your namespace,
$header = new SoapHeader('http://www.wwexship.com', 'AuthenticationToken', $headerbody, false);
回答2:
Well, i got the solution so posting it herewith .... atleast save this solution and send it to the affected users so that they can use it
Steps to test
- Create a PHP page
- Copy paste below code
- Change the user, pwd, acct# and key in the soap_request variable text...
- Code
========================
<?php
$url = "http://www.wwexship.com/webServices/services/SpeedFreightShipment";
$soap_request = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wwex="http://www.wwexship.com"> <soapenv:Header> <wwex:AuthenticationToken> <wwex:loginId>LOGIN_ID</wwex:loginId> <wwex:password>PASSWPRD</wwex:password> <wwex:licenseKey>LIC_KEY</wwex:licenseKey> <wwex:accountNumber>ACCT_NUMB</wwex:accountNumber> </wwex:AuthenticationToken> </soapenv:Header> <soapenv:Body> <wwex:quoteSpeedFreightShipment> <wwex:freightShipmentQuoteRequest> <wwex:insuranceDetail xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/> <wwex:senderState>AZ</wwex:senderState> <wwex:senderZip>85027</wwex:senderZip> <wwex:senderCountryCode>USA</wwex:senderCountryCode> <wwex:receiverState>NY</wwex:receiverState> <wwex:receiverZip>11428</wwex:receiverZip> <wwex:receiverCountryCode>USA</wwex:receiverCountryCode> <wwex:commdityDetails> <wwex:is11FeetShipment>N</wwex:is11FeetShipment> <wwex:handlingUnitDetails> <wwex:wsHandlingUnit> <wwex:typeOfHandlingUnit>Box</wwex:typeOfHandlingUnit> <wwex:numberOfHandlingUnit>1</wwex:numberOfHandlingUnit> <wwex:lineItemDetails> <wwex:wsLineItem> <wwex:lineItemHazmatInfo xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/><wwex:lineItemClass>50</wwex:lineItemClass> <wwex:lineItemWeight>1</wwex:lineItemWeight> <wwex:lineItemDescription>Diamond Box</wwex:lineItemDescription> <wwex:lineItemPieceType>Pallet</wwex:lineItemPieceType> <wwex:piecesOfLineItem>1</wwex:piecesOfLineItem> </wwex:wsLineItem> </wwex:lineItemDetails> </wwex:wsHandlingUnit> </wwex:handlingUnitDetails> </wwex:commdityDetails> </wwex:freightShipmentQuoteRequest> </wwex:quoteSpeedFreightShipment> </soapenv:Body> </soapenv:Envelope>';
$header = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"http://www.wwexship.com/webServices/services/SpeedFreightShipment\"",
"Content-length: ".strlen($soap_request),
);
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $url);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($soap_do);
echo "<pre>".$result."<pre>";
?>
===================================
For further help please get back @
http://www.linkedin.com/in/dramilmdodeja
Dramil Dodeja
来源:https://stackoverflow.com/questions/21520924/soap-header-is-not-being-set