php - Passing Authentication Credentials in SoapHeader class -
i have xml file in format below
<?php $xmlstr = <<<xml <?xml version="1.0" encoding="utf-8" ?> <soap:envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tusa="http://schemas.datacontract.org/2004/07/tusa.services.consumerconnect" xmlns:tem="http://tempuri.org/"> <soap:header> <authenticationcredentials> <tusa:password>xxxxx</tusa:password> <tusa:username>xxxxx</tusa:username> </authenticationcredentials> </soap:header> <soap:body> <tem:addproduct> <tem:customerdetail> <tusa:addressline1>52 test drive</tusa:addressline1> <tusa:city>johannesburg</tusa:city> <tusa:maritalstatus>unknown</tusa:maritalstatus> //more nodes </tem:customerdetail> </tem:addproduct> </soap:body> </soap:envelope> xml;
given following soap header
<soap:header> <authenticationcredentials> <tusa:password>xxxxx</tusa:password> <tusa:username>xxxxx</tusa:username> </authenticationcredentials> </soap:header>
how can pass username , password soapheader class. have tried using code below getting error
authentication credentials required
try { $auth = array( 'username'=>'xxxxx', 'password'=>'xxxxx', ); $client = new \soapclient('https://test.com//indirect.svc?wsdl', array('soap_version' => soap_1_2, 'trace' => 1)); $actionheader = new \soapheader('http://www.w3.org/2005/08/addressing', action', http://tempuri.org/iindirect/addproduct'); $client->__setsoapheaders($actionheader); $response = $client->addproduct($xmlstr); } catch (\exception $e) { echo "error!"; echo $e -> getmessage (); echo 'last response: '. $client->__getlastresponse(); }
i think you're looking this
$auth = [ 'username' => 'xxxxx', 'password' => 'xxxxx', ]; $ns = 'http://www.w3.org/2003/05/soap-envelope/'; $header = new soapheader($ns, 'authenticationcredentials', $auth); $client->__setsoapheaders($header);
Comments
Post a Comment