php - 使用php进行soapheader验证

标签 php soap soap-client soapheader

Possible Duplicate:
PHP SoapClient and a complex header

我有这个标题结构:

<soapenv:Header>
  <wsse:Security xmlns:wsse=”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd” soapenv:mustUnderstand=”0”>
    <wsse:UsernameToken>
    <wsse:Username Type=”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken”>votre_login</wsse:Username>
    <wsse:Password Type=”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText”>votre_password</wsse:Password>
    </wsse:UsernameToken>
  </wsse :Security>
</soapenv :Header>

我如何使用 __setSoapHeaders() 将其放入 php 中方法?

我尝试过:

$auth = array(
            'UsernameToken' => array(
                'Username' => '*****',
                'Password' => '*****'
            )
        );
$header = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd','Security',$auth, 0);
$client->__setSoapHeaders($header);

我有这个错误:

com.ibm.wsspi.wssecurity.SoapSecurityException: WSEC5509E: Un jeton de sécurité dont le type est [http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken] est requis.

最佳答案

来自:http://php.net/manual/en/soapclient.setsoapheaders.php#93460

To create complex SOAP Headers, you can do something like this:

Required SOAP Header:

<soap:Header> 
 <RequestorCredentials xmlns="http://namespace.example.com/"> 
  <Token>string</Token> 
  <Version>string</Version> 
  <MerchantID>string</MerchantID> 
  <UserCredentials> 
   <UserID>string</UserID> 
   <Password>string</Password> 
  </UserCredentials> 
 </RequestorCredentials> 
</soap:Header> 

Corresponding PHP code:

$ns = 'http://namespace.example.com/'; //Namespace of the WS. 

//Body of the Soap Header. 
$headerbody = array('Token' => $someToken, 
                'Version' => $someVersion, 
                'MerchantID'=>$someMerchantId, 
                  'UserCredentials'=>array('UserID'=>$UserID, 
                                         'Password'=>$Pwd)); 

//Create Soap Header.        
$header = new SOAPHeader($ns, 'RequestorCredentials', $headerbody);        

//set the Headers of Soap Client. 
$soap_client->__setSoapHeaders($header);

关于php - 使用php进行soapheader验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14161404/

相关文章:

php - 将日期替换为 x 格式的 php

xml - 使用 gowsdl 进行 SOAP 调用

c - 有 gSOAP 的轻量级替代品吗?

wsdl - WSP0075:策略断言“TransportBinding”被评估为“未知”。为什么?

php - PHP SoapClient 的复杂 header

c# - 如何拦截来自 C# 客户端 Web 代理的出站和入站 Soap 消息

php - 未定义索引 :logged in

php - wordpress侧边栏和循环php代码相互扭曲

php - 选择 SQL 中的问题

ruby-on-rails - 通过另一台机器请求