标头中带有登录名的soap php请求

标头中带有登录名的soap php请求,php,soap,soap-client,Php,Soap,Soap Client,我在PHP中使用SoapClient,我在一个小项目中遇到了一个小问题 我有以下WSDL在SOAP头中请求usernae/密码: 说明中说我必须在Soap头上传递用户名和密码,如下所示: <?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://gr/gsis/rgwspublic/RgW

我在PHP中使用SoapClient,我在一个小项目中遇到了一个小问题

我有以下
WSDL
SOAP
头中请求usernae/密码:

说明中说我必须在Soap头上传递用户名和密码,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="http://gr/gsis/rgwspublic/RgWsPublic.wsdl"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <env:Header> <ns1:Security> <ns1:UsernameToken> <ns1:Username>XXXXXXXXXXXXX</ns1:Username> <ns1:Password>YYYYYYYYYYY</ns1:Password> </ns1:UsernameToken> </ns1:Security> </env:Header>
<env:Body>
<ns:rgWsPublicVersionInfo/>
</env:Body>
</env:Envelope>
。。。我总是得到错误
RG\u WS\u PUBLIC\u TOKEN\u USERNAME\u NOT\u DEFINED

提前感谢您的帮助:)

亚历克斯

在反规范化程序的帮助下,我的代码如下(完整代码):

我一直在获取未定义的RG_WS_PUBLIC_TOKEN_USERNAME_(用户呼叫服务未定义)

感谢您的帮助。这东西弄得我乱七八糟。


嗯,我自己找到的,我把它贴在这里,以防其他人想知道如何正确设置auth头

    $client = new SoapClient( "***WSDL_URL***",array('trace' => true,'exceptions' => true, 'connection_timeout' => 1) );
    $authHeader = new stdClass();
    $authHeader->UsernameToken->Username = "**USERNAME**";
    $authHeader->UsernameToken->Password = "**PASSWORD**";
    $Headers[] = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', $authHeader,TRUE);
    $client->__setSoapHeaders($Headers);
$options['**OPTION1**'] = XXXXX
$options['**OPTION2**'] = XXXXX
    $result = $client->***METHOD_TO_CALL***($options);

嗯,我自己找到的,我把它贴在这里,以防其他人想知道如何正确设置auth头

    $client = new SoapClient( "***WSDL_URL***",array('trace' => true,'exceptions' => true, 'connection_timeout' => 1) );
    $authHeader = new stdClass();
    $authHeader->UsernameToken->Username = "**USERNAME**";
    $authHeader->UsernameToken->Password = "**PASSWORD**";
    $Headers[] = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', $authHeader,TRUE);
    $client->__setSoapHeaders($Headers);
$options['**OPTION1**'] = XXXXX
$options['**OPTION2**'] = XXXXX
    $result = $client->***METHOD_TO_CALL***($options);

您需要查看php soapheaders:我查看了soapheaders,但无法使其工作:(您需要查看php soapheaders:我查看了soapheaders,但无法使其工作:(我一直收到相同的错误RG_WS_PUBLIC_TOKEN_USERNAME_未定义。我正在将代码从开头复制到我的原始帖子。如果你能帮我,我欠你的!!我对这些东西非常着迷!看起来好像缺少
mustUnderstand
属性我一直收到相同的错误RG_WS_PUBLIC_TOKEN_USERNAME_未定义。我正在从从我原来的帖子开始。如果你能帮我,我欠你的!!我快被这些东西弄疯了!看起来好像缺少
mustUnderstand
attribute
$ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'; //Namespace of the WS.

//Body of the Soap Header. 
$headerbody = array(
  'UsernameToken' => array(
    'Username' => 'XXXXXXXXXXXXX',
    'Password' => 'YYYYYYYYYYY'
  )
);

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

//set the Headers of Soap Client.
$client->__setSoapHeaders($header);
$result = $client->rgWsPublicAfmMethod($params);
    $client = new SoapClient( "***WSDL_URL***",array('trace' => true,'exceptions' => true, 'connection_timeout' => 1) );
    $authHeader = new stdClass();
    $authHeader->UsernameToken->Username = "**USERNAME**";
    $authHeader->UsernameToken->Password = "**PASSWORD**";
    $Headers[] = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', $authHeader,TRUE);
    $client->__setSoapHeaders($Headers);
$options['**OPTION1**'] = XXXXX
$options['**OPTION2**'] = XXXXX
    $result = $client->***METHOD_TO_CALL***($options);