【发布时间】:2016-06-18 16:03:26
【问题描述】:
当我运行下面的代码时,我得到了错误:
file_get_contents(http://roblox.plus:2052/limiteds):打开失败 流:连接被拒绝
$file = file_get_contents('http://roblox.plus:2052/limiteds');
$decode = json_decode($file, false);
foreach($decode AS $person) {
echo $person->name . ": " . $person->lowestPrice . "<br><br>";
}
这是为什么?我可以通过浏览器正常访问该网站。我也试过PHP Fiddle上的代码。
在 cmets 之后,我尝试使用 cURL - 但是没有显示任何结果。
$url = 'http://roblox.plus:2052/limiteds';
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
// Decode
$decode = json_decode($result, false);
foreach($decode AS $person) {
echo $person->name . ": " . $person->lowestPrice . "<br><br>";
}
【问题讨论】:
-
是的,最好使用 cURL:forums.phpfreaks.com/topic/…
-
@bucketman 我尝试过使用 cURL。请查看我更新的帖子
-
你能从命令行做 curl 吗?
curl http://roblox.plus:2052/limiteds- 如果您发送的请求过多,他们可能会阻止您的服务器。 -
@bobjomes 许多虚拟主机(甚至共享)允许您通过 ssh 登录,或者至少在他们的网络界面中为您提供命令行。
标签: php json file-get-contents