PHP Soap身份验证标头

时间:2013-09-17 21:33:19

标签: php api soap

样品申请:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="https://ws.intermedia.net/Account/Management">

<soapenv:Header>
  <AuthentificationInfo>
     <login>[PLRAdminUserName]</login>
     <password>[PLRAdminPassword]</password>
     <accountID>[accountID]</accountID>
  </AuthentificationInfo>
</soapenv:Header>
<soapenv:Body>
  <GetAccount>
     <accountID>[accountID]</accountID>
  </GetAccount>
</soapenv:Body>
</soapenv:Envelope>

WSDL:https://controlpanel.msoutlookonline.net/WebServices/Account/AccountService.asmx?WSDL

PHP:

    ini_set("soap.wsdl_cache_enabled", "0");

    $wsdl = "https://controlpanel.msoutlookonline.net/WebServices/Account/AccountService.asmx?WSDL";
    $ns = 'https://ws.intermedia.net/Account/Management';

    $client = new SoapClient($wsdl, array(
        "trace" => 1,
        "exceptions" => 0
    ));

    $login = 'xxxx';
    $password = 'xxxx';
    $partnerID = 1234;
    $accountID = 12345678;

    $headerBody = array('AuthentificationInfo'=>array(
        'login' => $login,
        'password' => $password,
        'accountID' => $partnerID
    ));
    $header = new SoapHeader($ns, 'AuthentificationInfo', $headerBody);
    $client->__setSoapHeaders($header);
    $client->__soapCall("echoVoid", array(null));

    $value = $client->GetAccount($accountID);

我收到以下错误消息:

soap:ServerServer was unable to process request. ---> Access denied; Code: 0x0008

任何人都可以看到代码有什么问题吗?

3 个答案:

答案 0 :(得分:5)

尝试

     $headerBody = array(
      'login' => $login,
      'password' => $password,
      'accountID' => $partnerID);

答案 1 :(得分:2)

仅适用于可能遇到此问题的其他任何人:

我改变了

$ns = 'https://ws.intermedia.net/Account/Management';

为:

$ns = 'http://schemas.msoutlookonline.net';

答案 2 :(得分:1)

我的命名空间不正确。

MikaëlDELSOL的回答也有帮助,因为我不需要array('AuthentificationInfo'=>部分。 也不需要:$client->__soapCall("echoVoid", array(null));

谢谢!