doupai8095 2019-08-13 13:29
浏览 101

如何将凭据传递给PHP SOAP请求

I need to create a PHP SOAP client based on this specification:

https://exdev.server.propctrl.com/v5.4/Basic/AgencyIntegration.svc?wsdl

I am able to create my soap client, and when I try to call a function it returns saying access denied:

Message: Access is denied.

Based on documentation, there is no verification/auth method that I first need to call, but it seems I have to use a type called Credentials.

struct Credentials { string Password; string Username; }

I then tried created a Credentials object:

class Credentials {
  public function __construct($username, $password) 
  {
      $this->username = $username;
      $this->password = $password;
  }
}

And assigned new values to it and used it in my SoapHeaders:

$credentials = new Credentials($username, $password);
$header = new SoapHeader('http://localhost','Credentials',$credentials,false);
$client->__setSoapHeaders($header);

When I then use a function I still get the same error:

echo "<pre>";
try {
$response = $client->__soapCall("EchoAuthenticated", array("EchoAuthenticated" => "asdfasdf"));
var_dump($response);
}
//catch exception
catch(Exception $e) {
  echo 'Message: ' .$e->getMessage();
}

Message: Access is denied.

I guess my question is that I don't know where/how to pass through the credentials in order for the API to authorise my request.

Any ideas/suggestions?

update1:

enter image description here

  • 写回答

1条回答 默认 最新

  • dongsheng8158 2019-08-16 12:40
    关注

    The authentication method should be explained in some documentation, anyway there are Soap services that use HTTP Header for authentication, for example

                $soapClient->setHttpHeaders([
                    'clientId' => $username,
                    'clientSecret' => $password
                ]); 
    

    But please consider that keys ( in my example clientId and clientSecret ) depend by the service implementation. Do you have a service documentation?

    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题