在我的 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
我错过了什么?
最佳答案
您将请求数据传递到 SoapClient
的 options 内,而不是作为 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/