获取 json 内容时出现问题
嗨,我正在尝试从 json 文件中获取内容,但我不能,我有很多麻烦来做到这一点,我的代码是:
<?PHP
$url = 'http://www.taringa.net/api/efc6d445985d5c38c5515dfba8b74e74/json/Users-GetUserData/apptastico';
$ch = curl_init();
$timeout = 0; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch); // take out the spaces of curl statement!!
curl_close($ch);
var_dump($file_contents);
?>
如果我将地址放入浏览器中,我会毫无问题地获取内容,但如果我尝试在 PHP 或其他代码上获取它,但我遇到问题,我该怎么办?我尝试使用 file_get_contents();我也没有得到任何东西,只有问题和问题
Hi i'm trying to get the content from a json file, but i can't i have many troubles to do it, my code is:
<?PHP
$url = 'http://www.taringa.net/api/efc6d445985d5c38c5515dfba8b74e74/json/Users-GetUserData/apptastico';
$ch = curl_init();
$timeout = 0; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch); // take out the spaces of curl statement!!
curl_close($ch);
var_dump($file_contents);
?>
if i put the address in the browser i get the content without any issue, but if i try to get it on PHP or other code i have issues, what can i do? i try use file_get_contents(); too but i don't get anything, only issues and issues
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来他们正在检查用户代理并阻止 PHP。在使用 file_get_contents 之前设置:
如果他们正在检查用户代理,他们可能这样做是为了防止人们做这种事情。
It appears that they are checking user agents and blocking PHP. Set this before using file_get_contents:
If they are checking user agents, they may be doing so to prevent people from doing this kind of thing.
您在 php.net 上读过一些有关 cURL 的内容吗?
这是它的工作原理:
来自 php.net:
Have you read a little bit about cURL on php.net?
here is how it works:
From php.net: