Something strange is going on, and I would like to know why.
On this url: http://api.promasters.net.br/cotacao/v1/valores?moedas=USD&alt=json, which works well in the browser, but when I tried to retrieve the content with php:
echo file_get_contents('http://api.promasters.net.br/cotacao/v1/valores?moedas=USD&alt=json'); printed nothing, with var_dump(...) = string(0) "", so i went a little further and used:
function get_page($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, True); curl_setopt($curl, CURLOPT_URL, $url); $return = curl_exec($curl); curl_close($curl); return $return; } echo get_page('http://api.promasters.net.br/cotacao/v1/valores?moedas=USD&alt=json'); Also printed nothing, so i tried python (3.X):
import requests print(requests.get('http://api.promasters.net.br/cotacao/v1/valores?moedas=USD&alt=json').text) And WORKED. Why is this happening? What's going on?
echowon't print out the boolean false that you'd get back on failure. usevar_dumpinstead.echo file_get_contents('http://stackoverflow.com/questions/37548007/file-get-contents-curl-not-working?noredirect=1#comment62584729_37548007');and it workedvar_dump:string(0) "", i tried this toocurl_setopt($curl, CURLOPT_FOLLOWLOCATION, True);before the curl_exec