PHP SoapClient并创建标头

时间:2011-11-14 20:05:24

标签: php soap soap-client

我正在尝试使用PHP SOAP CLient创建自定义标头,它看起来像

  <soap:Header>
    <AuthorizationToken xmlns="http://www.avectra.com/OnDemand/2005/">
      <Token>string</Token>
    </AuthorizationToken>   </soap:Header>

我的代码如下:

      $client = new SoapClient("http://nftpsandbox.avectra.com/xweb/netFORUMXMLONDemand.asmx?WSDL",array("trace" => 1));

    try {

        $header = new SoapHeader('http://www.avectra.com/OnDemand/2005/', 'AuthorizationToken', $token, false);
        $client->__setSoapHeaders(array($header));              

        $result = $client->CheckEWebUser(array('szEmail' => $userName , 'szPassword' => $password));

    }
    catch (SoapFault $result)
    {
        echo $result->faultstring;
    }   

    catch   (Exception $result){
    } 

但是我得到的Request标题看起来像是:

<SOAP-ENV:Header>
  <ns1:AuthorizationToken>
     <ns1:Token></ns1:Token>
  </ns1:AuthorizationToken>
</SOAP-ENV:Header>

$token有值时,知道为什么节点令牌为空?

1 个答案:

答案 0 :(得分:3)

SimpleXMLLement可能难以处理,尝试传递stdClass的简单实例

$auth = new stdClass();
$auth->Token = '123';

$header = new SoapHeader('http://www.avectra.com/OnDemand/2005/', 'AuthorizationToken', $auth, false);