how to authenticate Soap Header in nusoap server in PHP?

浪尽此生 提交于 2019-12-25 02:46:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!