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 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题