Php 文件\u获取\u内容(http://roblox.plus:2052/limiteds):无法打开流:连接被拒绝

Php 文件\u获取\u内容(http://roblox.plus:2052/limiteds):无法打开流:连接被拒绝,php,json,file-get-contents,Php,Json,File Get Contents,当我运行下面的代码时,我得到了错误: 文件\u获取\u内容():无法打开 流:连接被拒绝 出于安全原因,许多主机会阻止您从远程URL加载文件。最好使用CURL下载文件的内容 我像下面那样尝试,效果很好 此文件\u获取\u内容方法: <?PHP $file = file_get_contents('http://roblox.plus:2052/limiteds'); $jsond = json_decode($file, true); foreach ($json

当我运行下面的代码时,我得到了错误:

文件\u获取\u内容():无法打开 流:连接被拒绝


出于安全原因,许多主机会阻止您从远程URL加载文件。最好使用CURL下载文件的内容

我像下面那样尝试,效果很好

此文件\u获取\u内容方法:

<?PHP
    $file = file_get_contents('http://roblox.plus:2052/limiteds');
    $jsond = json_decode($file, true);

    foreach ($jsond['data'] as $vals) {
        echo $name = $vals["name"].' ';
        echo $lowp = $vals["lowestPrice"].'<br>';    
    }
?>

可能的解决方案:是的,最好使用cURL:@bucketman我试过使用cURL。请检查我更新的postCan您是否从命令行执行卷曲<代码>卷曲http://roblox.plus:2052/limiteds-如果您发送了太多请求,他们可能会阻止您的服务器。@bobjomes的许多web主机(甚至是共享的)允许您通过ssh连接,或者至少在其web界面中为您提供一个命令行。你好,Ivan,感谢您的响应。您给我的第一个示例仍然显示与我最初收到的错误相同的错误。第二个有一个未识别的变量
$jsond
,第三个也显示相同的错误消息。在第二个示例中,将foreach($jsond['data']改为$vals){改为foreach($decode['data']改为$vals){并尝试一下。我已经按照您的建议对它进行了更改,现在它显示为foreach()提供的
参数无效--在第12行
我更新了它,复制粘贴第二个示例,然后重试。仍然是相同的问题
$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>";
}
<?PHP
    $file = file_get_contents('http://roblox.plus:2052/limiteds');
    $jsond = json_decode($file, true);

    foreach ($jsond['data'] as $vals) {
        echo $name = $vals["name"].' ';
        echo $lowp = $vals["lowestPrice"].'<br>';    
    }
?>
<?PHP
    $url = 'http://roblox.plus:2052/limiteds';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL,$url);
    $result=curl_exec($ch);
    curl_close($ch);

    $decode = json_decode($result, true);

    foreach ($decode['data'] as $vals) {
        echo $name = $vals["name"].' ';
        echo $lowp = $vals["lowestPrice"].'<br>';
    }
?>
<?php
    // Create a stream
    $opts = array(
            'http'=>array(
                    'method'=>"GET",
                    'header'=>"Accept-language: en\r\n" .
                            "Cookie: foo=bar\r\n"
            )
    );

    $context = stream_context_create($opts);

    // Open the file using the HTTP headers set above
    $file = file_get_contents('http://roblox.plus:2052/limiteds', false, $context);
    $jsond = json_decode($file, true);

    foreach ($jsond['data'] as $vals) {
       echo $name = $vals["name"].' ';
       echo $lowp = $vals["lowestPrice"].'<br>';    
    }
?>
Red Baseball Cap 94
Classic ROBLOX Viking Helm 825
The Classic ROBLOX Fedora 30000
Domino Crown 4300000
Princess Hat 585
The Agonizingly Ugly Yellow Baseball Cap 1398
Jester's Cap 1355
Flag 699999
ROBLOX Classic: Wizard's Hat 599
Tornado Hat 1200
Target Hat 345
JJ5x5's White Top Hat 37142
Bucket 3899
Got Milk Visor 2497
Police Sergeants Cap 6000