Fatal error: Uncaught SoapFault exception: [ns1:Client.AUTH_1] Authentication Failed

前端 未结 2 1521
我寻月下人不归
我寻月下人不归 2021-01-22 13:12

In my wsdl file I have a user authentication block:



    
        

        
相关标签:
2条回答
  • 2021-01-22 13:56

    You're passing your request data inside options for SoapClient instead of as parameters to the soap call.

    The code should look like this (assuming the soap call is Authenticate):

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

    And, in any event, you should use try..catch to prevent exceptions from crashing your code.

    try
    {
       // code here
    }
    catch(Exception $e)
    {
       // error handling goes here
       die("Error: ". $e->getMessage()."\n");
    }
    
    0 讨论(0)
  • 2021-01-22 14:03

    Without the full WSDL specification it's hard to tell where the issue is. But my guess is you're looking at the specs. wrong. Probably those are headers that need to be sent, not actual methods that need to be called.

    So try with something like this:

    // SOAP client options
    $options = array(
        'soap_version' => SOAP_1_2,
        'trace'        => true,
    );
    
    // initialise the SOAP client
    $apiURL = 'http://api.example.com/v2/example?wsdl';
    $namespace = 'http://api.example.com/v2/example?wsdl';
    
    $client = new SoapClient($apiURL, $options);
    
    // the SOAP headers
    $headers = array();
    
    $ua = array(
        'iId' => 123456,
        'sPassword' => 'fhfhfhfhfhfhfh46464dtdts64iyiyi', 
        'sType' => 'ghfh57477gghdkskdk68585jghhddhdghds',
    );
    
    $headers[] = new SoapHeader($namespace, 'UserAuthentication', $ua);
    
    // we could add multiple headers if needed
    
    $client->__setSoapHeaders($headers);
    
    // call the API function
    $response = $client->__soapCall("whateverYourTryingToCall", null);
    
    0 讨论(0)
提交回复
热议问题