file_get_contents无效,但文件存在于浏览器

时间:2015-12-31 04:44:43

标签: php

以下是我的代码似乎无法正常工作。

$addy = "http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Tec-9%20%7C%20Isaac%20%28Field-Tested%29";
$price = json_decode(file_get_contents($addy));

$price仍为NULL,我收到以下错误

  

警告:file_get_contents(http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Tec-9%20%7C%20Isaac%20%28Field-Tested%29):无法打开流:HTTP请求失败! HTTP / 1.0 429未知......

但是,如果您转到浏览器中的网址,该文件肯定存在http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Tec-9%20%7C%20Isaac%20%28Field-Tested%29

我不相信它是一个安全问题,因为我也尝试过使用CURL。 PHP是否会处理与浏览器不同的链接?

2 个答案:

答案 0 :(得分:0)

请在下面的代码。

$addy = "https://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Tec-9%20%7C%20Isaac%20%28Field-Tested%29";
$pricefiledata = file_get_contents($addy);
$price = json_decode($pricefiledata);
echo "<pre>";
print_r($price);
echo "<br />";
echo "<br />Price --->".$price->lowest_price;

输出显示如下。

stdClass Object
(
    [success] => 1
    [lowest_price] => $0.21
    [volume] => 1,422
    [median_price] => $0.21
)
Price --->$0.21

答案 1 :(得分:0)

服务器的错误响应为429。这是一个服务器端错误,它会阻止像我试图开发的那样的脚本(esentailly我试图经常请求很多)。这就是脚本在本地工作的原因。