问题
I am trying to make stub server of .net soap service in php by using nusoap. I am not able to authenticate the header in my PHP code. Sample Xml is
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthenticationHeader xmlns="http://tempuri.org/">
<UserName>string</UserName>
<Password>string</Password>
</AuthenticationHeader>
</soap:Header>
<soap:Body>
<getUserPackDetails xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
Should i parse the soap header as a complex type or there is any other way?
回答1:
For soap header i was not able to find any function in nusoap but we could authenticate header by getting receive contents by PHP.
function doAuthenticate()
{
$sSoapRequest = file_get_contents('php://input');
if(isset($sSoapRequest))
{
$sUsername = hookTextBetweenTags($sSoapRequest, 'Username');
$sPassword = hookTextBetweenTags($sSoapRequest, 'Password');
if($sUsername=='testuser' && $sPassword=='test12345')
return true;
else
return false;
}
}
function hookTextBetweenTags($string, $tagname) {
$pattern = "/<$tagname ?.*>(.*)<\/$tagname>/";
preg_match($pattern, $string, $matches);
return $matches[1];
}
来源:https://stackoverflow.com/questions/23629731/how-to-authenticate-soap-header-in-nusoap-server-in-php