Search code examples
phpsoapsoap-client

SOAP: Add user and password to the soap:address location URL doesn't work?


When I curl this url, It works :

curl http://OLM:OLM794%24@X.XXX.XXX.XXX:10080

But, when I call it in my soap address like this, it doesn't work :

<soap:address location="http://OLM:OLM794%24@X.XXX.XXX.XXX:10080/"/>

It shows me : (SoapFault): Authorization Required

Have you an idea why ?

Update:

sw.xml

....
<wsdl:service name="Toto">
        <wsdl:port name="GazListeImpayesHttpSoap11Endpoint" binding="tns:TotoSoap11Binding">
            <soap:address location="http://OLM:OLM794%24@X.XXX.XXX.XXX:10080/web/services/Toto.TotoHttpSoap11Endpoint/"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

Then in my file that calls that soap:

file.php

<?php
$soap = new SoapClient('http://domaine.com/sw.xml');

var_dump($soap->__getFunctions()); //OK
var_dump($soap->__getTypes()); //OK

$result = $soap->__soapCall("method", array("parameters"=>array("args0"=>array("NUM"=> "123"))));
var_dump($result);
?>

result:

(SoapFault): Authorization Required

Solution

  • I found the solution, the user and password should be added in the SoapClient method and not directly in wsdl soap:address location

    like this:

    $user = "your user here";
    $password = "your password here";
    $url = "path of wsdl location here";
    $credentials = array(
        'login' => $user,
        'password' => $password,
    );
    
    $soap = new SoapClient($url, $credentials);