Basic Auth to authenticate webservice soap - PHP

1

I'm having a problem with authentication when I try to consume a web service soap. When entering with the url in the browser, it appears u dailog requesting user and password. But I need to do this authentication without this dialog being presented, that is, all authentication in the back end. I tried to pass the login and password through SoapHeader but without success. Here's the script:

!IMPORTANT: O tipo de autenticação é (Basic auth)    

$credenciais = self::fncGeraAuth();   
//array que contem user e senha para autenticação    
//Array ( [UserName] => xxxxx [Password] => xxxxx) 

$_rCliente2 = new SoapClient($wsdl, array("encoding" => "ISO-8859-1"));  

$Header = new SoapHeader($wsdl,'Authorization', $credenciais, false);

$_rCliente2->__setSoapHeaders($Header);

$result = $_rCliente2->fncRecuperaPapel($Instituição);
//tentado acessar uma função do webservice passando um parametro 

var_dump($result);
exit();

Erro:
SoapFault: SOAP-ERROR: Parsing WSDL: Couldn't load from '
...........?wsdl' : failed to load external entity ".........wsdl" 
    
asked by anonymous 31.08.2018 / 18:11

1 answer

0

Good afternoon!

I ran a quick test locally with a wsdl service done in PHP using Basic Auth HTTP.

I was able to authenticate by passing the login and password directly into SoapClient .

$client = new SoapClient('http://teste-soap.local/server.php?wsdl',['trace'=>1,'cache_wsdl'=>WSDL_CACHE_NONE, 'login' => 'adriano', 'password' => 'maciel']);

I also tried to use SoapHeader , but this does not work in this case, as authentication must be done when instantiating the client.

    
31.08.2018 / 19:14