我试图从ULR中获得一个JSON,但是我得到了错误:
file_get_contents(http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market™警告:file_get_contents(http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market™5-7铜银河(工厂新建):未能打开流: HTTP请求失败!F:\Bitnami\htdocs\Dreamweaver\freehtml5streets\updateInventory.php第70行中的HTTP/1.0 500内部服务器错误
这是我试图使用的URL,因为您可以看到如果您访问它,它会工作(您必须复制整个东西):
name=StatTrak™五七铜银河(新建工厂)
我一直在访问类似的URL并获得JSON,例如:
name=AK-47%20%7C%20Redline%20%28Field-Tested%29
这些URL基本相同,但第一个URL没有HTML标记。这是我的代码:
$data = file_get_contents('http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=' . $mydata->market_hash_name);
$json = json_decode($data);$mydata->market_hash_name会给我在网址末尾的部分,但是没有HTML (%20%)等等。
我怎么才能让这个起作用?
发布于 2015-05-09 14:14:49
看来您需要urlencode您的$mydata->market_hash_name,因为它使用了许多特殊的和保留的字符。下列措施应能发挥作用:
//Assuming $mydata->market_hash_name == "StatTrak™ Five-SeveN | Copper Galaxy (Factory New)"
$data = file_get_contents('http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=' . urlencode($mydata->market_hash_name));
$json = json_decode($data);发布于 2015-05-09 14:25:31
对于某些域,您可能发现无法使用此方法( file_get_contents )检索url,因为远程服务器正在期待一个有效的用户代理--在我看来,最好使用cURL获取远程页面的内容.
https://stackoverflow.com/questions/30140816
复制相似问题