Hi all,
I'm started to create a PHP application to fetch SiteCatalyst data to present it in a different way.
To begin with I just want to open a connection, but I get the error: Could not retrieve authentication credentials from SOAP header
when printing the XML it return.
My code look like this:
<?
// SOAP login credentials
$systemUsername = 'username';
$systemPassword = 'password';
$systemReportSuite = 'reportsuite';
$systemWSDLFile = "path-to-wsdl-file";
function get_header($username, $password) {
$nonce = md5(rand());
$created = date("Y-m-d H:i:s");
$combo_string = $nonce . $created . $password;
$sha1_string = sha1($combo_string);
$password = base64_encode($sha1_string);
$headers = '
<wsse:Security SOAP-ENV:mustUnderstand="1">
<wsse:UsernameToken wsu:Id="User">
<wsse:Username>'.$username.'</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">'.$password.'</wsse:Password>
<wsse:Nonce>'.$nonce.'</wsse:Nonce>
<wsu:Created>'.$created.'</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>';
return $headers;
}
$client = new SoapClient($systemWSDLFile);
$soapResponse = $client->__doRequest(
get_header($systemUsername, $systemPassword),
"https://api.omniture.com/admin/1.2/",
"Company.GetTokenCount",
1);
$domSOAPResponse = new DOMDocument();
$domSOAPResponse->loadXML($soapResponse);
?>
Do anyone here got the same problem and found a solution?
Best Regards,
Thomas
My solution
Hi,
Yes I found a solution.
You have to remove the hard returns in the string $headers.
This one worked for me:
$headers = '
<wsse:Security SOAP-ENV:mustUnderstand="1">
<wsse:UsernameToken wsu:Id="User">
<wsse:Username>'.$username.'</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">'.$password.'</wsse:Password>
<wsse:Nonce>'.$nonce.'</wsse:Nonce>
<wsu:Created>'.$created.'</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>';