肥皂php请求登录标题

时间:2017-06-16 16:44:30

标签: php soap soap-client

我在PHP中使用SoapClient,我对一个小项目有一个小问题。

我有以下WSDL请求SOAP标题中的用户/密码:

https://www1.gsis.gr/webtax2/wsgsis/RgWsPublic/RgWsPublicPort?WSDL

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

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

我使用以下内容。我尝试了几十种不同的方法,但没有运气!

$options = array ('trace' => true, 'exceptions' => true, 'connection_timeout' => 5, 'Username' => 'XXXXXXX', 'Password' => 'XXXXXXX');
$client = new SoapClient("https://www1.gsis.gr/webtax2/wsgsis/RgWsPublic/RgWsPublicPort?WSDL",$options);
$params['afmCalledFor'] = 'XXXXXX';
$params['afmCalledBy'] = 'XXXXXX';
$result = $client->rgWsPublicAfmMethod($params);
print_r($result);

...我总是收到错误RG_WS_PUBLIC_TOKEN_USERNAME_NOT_DEFINED

提前感谢您的帮助:)。

亚历

在Denormalizer的帮助下,我的代码就像这样(完整的代码):

$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' => '*******',
    'Password' => '*******'
  )
);

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

$options = array ('trace' => true, 'exceptions' => true, 'connection_timeout' => 5);
$client = new SoapClient("https://www1.gsis.gr/webtax2/wsgsis/RgWsPublic/RgWsPublicPort?WSDL",$options);

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

$params['afmCalledFor'] = '**********';
$params['afmCalledBy'] = '**********';
$result = $client->rgWsPublicAfmMethod($params);
print_r($result);

我一直收到RG_WS_PUBLIC_TOKEN_USERNAME_NOT_DEFINED(未定义用户呼叫服务)。

感谢任何帮助。我对这些东西很混乱。

2 个答案:

答案 0 :(得分:0)

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

$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);

答案 1 :(得分:0)

好吧,我自己发现了,我在这里发布,以防其他人想知道如何正确设置auth标头。

public void onDraw(Canvas canvas) {
  canvas.drawBitmap(inMemoryBitmap, 0, 0, paint);
}
相关问题