Reputation: 13
It is a simple json containing states of a country, when accessing directly from the browser works normally. But when trying to consume by curl, the result is null. Here's my code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , false);
curl_setopt($ch, CURLOPT_URL, "http://servicodados.ibge.gov.br/api/v1/localidades/estados");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=utf-8") );
$result = curl_exec($ch);
curl_close($ch);
$estados = json_decode($result, true);
print_r($estados);
die();
Upvotes: 0
Views: 35
Reputation: 1632
It seems that the response is binary, you can add this option as well to get the expected result.
curl_setopt($ch,CURLOPT_ENCODING , "");
Upvotes: 1