php - fatal error : Uncaught SoapFault exception: [ns1:Client. AUTH_1] 身份验证失败

标签 php soap

在我的 wsdl 文件中,我有一个用户身份验证 block :

<!-- User authentication -->

    <element name="UserAuthentication">
        <complexType>
            <sequence>
                <element name="iId" type="xsd:int" />
                <element name="sPassword" type="xsd:string" />
                <element name="sType" type="api:UserType" />
            </sequence>
        </complexType>
    </element>

我正在尝试实例化一个 SOAP 调用,如下所示:

$client = new SoapClient("http://api.example.com/v2/example?wsdl",
    array(
         'iId' => 123456, 
         'sPassword' => 'fhfhfhfhfhfhfh46464dtdts64iyiyi', 
         'sType' => 'ghfh57477gghdkskdk68585jghhddhdghds'));

提供真实值。脚本报告:

SoapFault exception: [ns1:Client.AUTH_1] Authentication Failed in

我错过了什么?

最佳答案

您将请求数据传递到 SoapClientoptions 内,而不是作为 SOAP 调用的参数。

代码应如下所示(假设 SOAP 调用是Authenticate):

$client = new SoapClient("http://api.example.com/v2/example?wsdl");

$response = $client->Authenticate(Array(
   'iId' => 123456, 
   'sPassword' => 'fhfhfhfhfhfhfh46464dtdts64iyiyi', 
   'sType' => 'ghfh57477gghdkskdk68585jghhddhdghds'));
   ));

并且,无论如何,您应该使用 try..catch 来防止异常导致代码崩溃。

try
{
   // code here
}
catch(Exception $e)
{
   // error handling goes here
   die("Error: ". $e->getMessage()."\n");
}

关于php - fatal error : Uncaught SoapFault exception: [ns1:Client. AUTH_1] 身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22096638/

相关文章:

php - 这个 PHPUnit 测试是否有意义(或者我正在测试框架/PHP)?

php - 如何重写我的 PHP 和 MySQL 以按相等的列值对我的 HTML 列表进行分组?

javascript - AngularJS SOAP 调用

soap - 使用 GSoap 和 SSL 时遇到问题

php - 使用 PHP simpleXML 查找我知道名称但不知道其所在位置的节点

javascript - 仅加载内容

PHP PDO - 没有事件事务

wcf - 提高 WCF 性能

grails - 如何通过像 Fiddler 这样的代理使用 intellij/grails 和 wslite soap 客户端来查看消息?

c# - 如何使用 C# 中使用 Datahandler 类型的基于 Java 的 SOAP 服务