使用wss头的Guzzle SOAP请求。

问题描述 投票:0回答:1

我需要在Guzzle SOAP请求中设置一个新的认证头。

$header = '<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:UsernameToken>
                <wsse:Username>' . $this->xiPayUser . '</wsse:Username>
                <wsse:Password>' . $this->xiPayPass . '</wsse:Password>
        </wsse:UsernameToken>
        </wsse:Security>
        <wsa:Action 
                xmlns:wsa="http://www.w3.org/2005/08/addressing">
                Paymetric/XiPaySoap30/action/XiGGE.SoapOp</wsa:Action>';

目前,我有这个。

$response = $this->httpClient->post($this->configuration['xipay_wsdl'], [
  'auth' => [
    $this->configuration['xipay_user'],
    $this->configuration['xipay_pass'],
    'ntlm',
  ],
  'body' => $xml,
  'headers' => [
    'Content-Type' => 'application/soap+xml; charset=utf-8',
    'SOAPAction' => 'Paymetric/XiPaySoap30/action/XiGGE.SoapOp',
  ],
]);

如何转换请求以使用新的头,我认为要删除当前的auth参数?

php security soap header guzzle
1个回答
0
投票

我找到了自己问题的解决方法,问题是对Guzzle库的误解,在Guzzle中,我们的请求头是标准的HTTP头,如果要发送SOAP头,就必须把它包含在我们发送的$xml中,变成请求的参数'body'。所以在$xml中,我们必须发送完整的SOAP XML,在这种情况下,我是使用SOAP头文件来验证服务,所以我把头文件添加到XML中,并从Guzzle请求中删除了'auth'参数,同时我还必须将内容类型头文件改为'Content-Type' => 'textxml; charset=utf-8'。

© www.soinside.com 2019 - 2024. All rights reserved.