SOAP authentication with PHP

前端 未结 2 1239
余生分开走
余生分开走 2020-12-16 06:17

I need to connect to a web service that requires authentication credentials in the form of a plain text user name and password.

I have a basic understanding of SOAP

相关标签:
2条回答
  • 2020-12-16 06:23

    If you have the SOAP extension enabled in php (php version >= 5.0.1), you can use the SoapClient class to process your request. To authenticate, you can pass the username and password to the class with the target URL:

    $soapURL = "https://www.example.com/soapapi.asmx?wsdl" ;
    $soapParameters = Array('login' => "myusername", 'password' => "mypassword") ;
    $soapFunction = "someFunction" ;
    $soapFunctionParameters = Array('param1' => 42, 'param2' => "Search") ;
    
    $soapClient = new SoapClient($soapURL, $soapParameters);
    
    $soapResult = $soapClient->__soapCall($soapFunction, $soapFunctionParameters) ;
    
    if(is_array($soapResult) && isset($soapResult['someFunctionResult'])) {
        // Process result.
    } else {
        // Unexpected result
        if(function_exists("debug_message")) {
            debug_message("Unexpected soapResult for {$soapFunction}: ".print_r($soapResult, TRUE)) ;
        }
    }
    

    If you're not sure about the functions you can call, you can view the target URL (e.g. ending in ".asmx?wsdl") in your browser. You should get an XML response that tells you the available SOAP functions you can call, and the expected parameters of those functions.

    0 讨论(0)
  • 2020-12-16 06:23

    Check out the soap_wsse library

    0 讨论(0)
提交回复
热议问题