Tarilonte
Tarilonte

Reputation: 71

php curl not retrieving as expected

I have the following code to capture the html code of a given url:

$url = "https://fnet.bmfbovespa.com.br/fnet/publico/exibirDocumento?id=77212&cvm=true";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_CAINFO, '/etc/ssl/certs/cacert.pem');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

    $html = curl_exec($ch);

    echo "$url\n\n";
    die($html); 

For some reason the result of the following url is not as expected:

"https://fnet.bmfbovespa.com.br/fnet/publico/exibirDocumento?id=77212&cvm=true"

Instead of the code, the result is a giant meaningless string.

My question is: There is any cUrl option that i should set to correct this error?

My whole site depends on capturing this pages. Any help would be truly appreciated.

Upvotes: 0

Views: 41

Answers (1)

RiggsFolly
RiggsFolly

Reputation: 94662

That is base64 encoded, all you need to do is decode it back to plain text like this

echo base64_decode($html);

and you will see HTML

Upvotes: 2

Related Questions