下面是我的代码,它似乎不起作用。
$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%28现场测试%29):无法打开流:HTTP请求失败!HTTP/1.0 429…中未知
但是,如果你转到浏览器中的网址,该文件肯定存在http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Tec-9%20%7C%20Isaac%20%28现场测试%29
我不认为这是安全问题,因为我也尝试过CURL。PHP对待链接的方式与浏览器不同吗?
请在下面的代码中。
$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
服务器的错误响应为429。这是一个服务器端错误,它阻止了像我试图开发的脚本一样的脚本(当然,我已经尝试过多次请求)。这就是脚本在本地工作的原因。