没有标头凭据的 XML Soap 请求

所以我知道有很多关于这个问题的问题,但每个问题都适用于标题。我有一个没有标头的 SOAP 请求:


<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="https://www.onderdelenlijn.nl/services/cars/v2.asmx">

   <soapenv:Header/>

   <soapenv:Body>

      <v2:airbags_get>

         <v2:credentials>

            <!--Optional:-->

            <v2:username>admin</v2:username>

            <!--Optional:-->

            <v2:password>adminpass</v2:password>

         </v2:credentials>

      </v2:airbags_get>

   </soapenv:Body>

</soapenv:Envelope>

我正在尝试使用以下代码通过正文进行身份验证:


<?php

$client = new SoapClient('https://www.onderdelenlijn.nl/services/cars/v2.asmx?wsdl');


$soapmessage = [

        'credentials' => [

            'username' => 'admin',

            'password' => 'adminpass'

        ]

];


$result = $client->airbags_get($soapmessage);

print_r($result);

?>

需要明确的是:正常的SOAP请求需要在标头中进行身份验证,我没有?


错误:未捕获的肥皂保险箱异常:[客户端] SOAP 错误:编码:对象没有“参数”属性


y


开心每一天1111
浏览 73回答 1
1回答

料青山看我应如是

您在 soap 消息中缺少预期值:parameters$soapmessage = [&nbsp; 'credentials' => [&nbsp; &nbsp; 'username' => 'admin',&nbsp; &nbsp; 'password' => 'adminpass'&nbsp; ],&nbsp; // Add this&nbsp; 'parameters'&nbsp; =>&nbsp; [&nbsp;&nbsp; &nbsp; 'culture'&nbsp; =>&nbsp; 'en',&nbsp; &nbsp; 'airbagid' =>&nbsp; 1,&nbsp; ],];如果您查看 soap URL,则可以看到示例请求:<soap:Body>&nbsp; <airbags_get xmlns="https://www.onderdelenlijn.nl/services/cars/v2.asmx">&nbsp; &nbsp; <credentials>&nbsp; &nbsp; &nbsp; <username>string</username>&nbsp; &nbsp; &nbsp; <password>string</password>&nbsp; &nbsp; </credentials>&nbsp; &nbsp; <parameters>&nbsp; &nbsp; &nbsp; <culture>nl or en or de or fr or es or pl</culture>&nbsp; &nbsp; &nbsp; <airbagid>int</airbagid>&nbsp; &nbsp; </parameters>&nbsp; </airbags_get></soap:Body>因此,您的完整代码将如下所示:$client = new SoapClient('https://www.onderdelenlijn.nl/services/cars/v2.asmx?wsdl');$soapmessage = [&nbsp; 'credentials' => [&nbsp; &nbsp; 'username' => 'admin',&nbsp; &nbsp; 'password' => 'adminpass'&nbsp; ],&nbsp; 'parameters'&nbsp; =>&nbsp; [&nbsp; &nbsp; 'culture' =>&nbsp; 'en',&nbsp; &nbsp; 'airbagid' =>&nbsp; 1,&nbsp; ],];$result = $client->airbags_get($soapmessage);print_r($result);
打开App,查看更多内容
随时随地看视频慕课网APP