【问题标题】:how to authenticate Soap Header in nusoap server in PHP?如何在 PHP 的 nusoap 服务器中验证 Soap Header?
【发布时间】:2014-05-13 11:16:38
【问题描述】:

我正在尝试使用 nusoap 在 php 中制作 .net soap 服务的存根服务器。我无法验证我的 PHP 代码中的标头。 样本 Xml 是

<?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>

我应该将soap头解析为复杂类型还是有其他方法?

【问题讨论】:

    标签: php soap nusoap


    【解决方案1】:

    对于soap标头,我无法在nusoap中找到任何函数,但我们可以通过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];
    }
    

    【讨论】:

      猜你喜欢
      • 2012-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-23
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 2015-09-20
      相关资源
      最近更新 更多