auth标头时出现问题

auth标头时出现问题

本文介绍了在php中发送SOAP auth标头时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对SOAP非常陌生(即毫无头绪!)

I am very new to SOAP (i.e. no clue!)

客户端已要求我与需要通过我的SOAP标头(简单的用户名和密码)进行身份验证的现有SOAP服务进行交互

I have been asked by a client to interact with an existing SOAP service that requires authentication done through my SOAP headers ( a simple username and password )

我有3种方法可供选择

还活着IsAliveSecureChangeUserDetails

IsAliveIsAliveSecureChangeUserDetails

IsAlive只是返回true,我可以称它为没问题

IsAlive simply returns true and I can call it no problem

IsAliveSecure在获得适当授权的情况下返回true,但我无法使其返回true.

IsAliveSecure returns true with proper authorisation and I cannot get it to return true.

基本上,我需要发送以下请求:

basically I need to send the following request:

POST /ripplecomprovisioning.asmx HTTP/1.1
Host: provisioning.example.ie
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.blueface.ie/provisioning/IsAliveSecure"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <SoapAuthHeader xmlns="http://www.example.ie/provisioning/">
      <Username>myusername</Username>
      <Password>mypassword</Password>
    </SoapAuthHeader>
  </soap:Header>
  <soap:Body>
    <IsAliveSecure xmlns="http://www.example.ie/provisioning/" />
  </soap:Body>
</soap:Envelope>

我的问题是如何在php中发送格式如上的请求?

My question is how do I send a request formatted like the above in php?

这是我尝试过但没有成功的事情:

this is what I tried but with no success:

$ soapClient = new SoapClient("https://provisioning.example.ie/ripplecomprovisioning.asmx?WSDL");

$soapClient = new SoapClient("https://provisioning.example.ie/ripplecomprovisioning.asmx?WSDL");

// Prepare SoapHeader parameters
$sh_param = array(
            'Username'    =>    'myusername',
            'Password'    =>    'mypassword');
$headers = new SoapHeader('ripplecomprovisioning', 'SoapAuthHeaders', $sh_param);

// Prepare Soap Client
$soapClient->__setSoapHeaders(array($headers));
     $result = $soapClient->isAlive();

echo var_dump($result);

echo "<br /><br />";

   $result = $soapClient->IsAliveSecure();

echo var_dump($result);

上面的输出如下:

object(stdClass)#3 (1) {
  ["IsAliveResult"]=>
  bool(true)
}
<br /><br />
Fatal error: Uncaught SoapFault exception: [soap:Server] System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
   at example.VoIP.Provisioning.RipplecomProvisioningServices.IsAliveSecure()
   --- End of inner exception stack trace --- in /var/www/ripplecomweb/authentication/soap.php:20
Stack trace:
#0 [internal function]: SoapClient->__call('IsAliveSecure', Array)
#1 /var/www/ripplecomweb/authentication/soap.php(20): SoapClient->IsAliveSecure()
#2 {main}
  thrown in /var/www/ripplecomweb/authentication/soap.php on line 20

任何对此的帮助将不胜感激.我承受不起失败!

Any help with this would be greatly appreciated. I cannot afford to fail!!

谢谢

Kev

推荐答案

如果我们可以看到该服务的WSDL,它将容易得多.但是,请尝试以下步骤:

Well it would be a lot easier if we could see the WSDL of the service.But try these steps:

1.检查WSDL中的isAliveSecure方法,以查看是否必须向其传递内容.

1.Check the WSDL for the isAliveSecure method to see if you have to pass something to it.

2.查看您发送的请求的真实外观:

2.See what the request you're sending really looks like:

var_dump($soapClient->__getLastRequest());
var_dump($soapClient->__getLastRequestHeaders());

(请确保对于这些方法,使用选项'trace' => TRUE实例化$soapClient,否则它们将不起作用->请参见 PHP手册).

(make sure you're instantiating $soapClient with the option 'trace' => TRUE for these methods or they won't work -> see PHP manual).

3.尝试以您确定应该通过命令行手动正确的形式发送请求,例如:

3.Try sending the request in the form that you're sure should be correct manually via command line, something like:

curl -v -k -d @/path/to/the/file/with/the/request/xml http://service_url

这篇关于在php中发送SOAP auth标头时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 10:36