Good afternoon,
I am running queries on a central bank webservice and am encountering some difficulties. The return of the query is in XML and I must send the authentication to receive this data, so far so good. The problem is in return if I make the request in POSTMAN it gives me this return:
ButdoingthePHPrequestreturnsmeemptywithvar_dump()likethis:
object(SimpleXMLElement)#40(0){}
code:
functionconsultaScr($cliente,$dataBase){$url="www3.bcb.gov.br/wsscr2/services/Scr2WebService/getResumoDoCliente?dataBase=$dataBase&codCliente=$cliente&tpCliente=1&autorizacao=S";
$username = getenv('USERNAME_SCR');
$password = getenv('PASSWORD_SCR');
$xml = file_get_contents("https://$username:$password@$url");
var_dump($xml);
}
If I get the $ xml variable and write it to a txt file it has the same content as POSTMAN, but even if I generate an .xml file with the fopen () function and after reading this same, it returns empty!
Another detail if I give an echo $ xml, it returns me the content however in string format without the tags.
I do not know what I'm doing wrong. Thanks in advance for your help.
FULL XML READING AND RECORDING PROCESS
function consultaScr($cliente, $dataBase)
{
$url = "www3.bcb.gov.br/wsscr2/services/Scr2WebService/getResumoDoCliente?dataBase=$dataBase&codCliente=$cliente&tpCliente=1&autorizacao=S";
$username = getenv('USERNAME_SCR');
$password = getenv('PASSWORD_SCR');
$xml = file_get_contents("https://$username:$password@$url");
$fp = fopen('consulta.xml', 'w+');
fwrite($fp, $xml);
fclose($fp);
$arquivo_xml = simplexml_load_file('consulta.xml');
var_dump($arquivo_xml);
}