0
Good afternoon,
I’m doing consultations 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 the return if I make the request in POSTMAN he gives me this return:
But making the request by PHP it returns me empty with var_dump() like this:
object(SimpleXMLElement)#40 (0) { }
code:
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");
var_dump($xml);
}
If I take the $xml variable and write it in a txt file it has the same content as POSTMAN, but even if I generate a file. xml with the fopen() function and after reading it, returns empty!
Another detail if I give an echo $xml, it returns the content but in string format without the tags.
I don’t know what I’m doing wrong. I appreciate the help.
FULL PROCESS OF READING AND WRITING IN XML
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);
}
I put the full code there.
– David Santos