【发布时间】:2016-06-12 14:52:45
【问题描述】:
我正在尝试获取此 json 的内容:http://steamcommunity.com/market/pricehistory/?country=DE¤cy=3&appid=730&market_hash_name=Chroma%20Case
这是我的代码:
$url = "http://steamcommunity.com/market/pricehistory/?country=DE¤cy=3&appid=730&market_hash_name=Chroma%20Case";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, 'steamLogin = 76561198075419487%7C%7C3F1A776553C4BE1D0F6DA83059052E79DB7EB3C7');
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$json_string = json_encode($output, JSON_PRETTY_PRINT);
当打印出$json_string 时,它不会产生任何结果,$output 会产生“‹ŠŽÿÿ)»L”。我想获取网站上的实际内容,为此需要steamLogin-Cookie。目前存储在我浏览器中的 cookie 是我在源代码中硬编码的那个。
如果您需要更多信息,请随时询问。
【问题讨论】:
-
尝试添加
curl_setopt($ch, CURLOPT_ENCODING, "");(以处理被压缩的响应)- cookie 中=周围的空间看起来不对。 -
@AlexK。谢谢!这真的成功了! :)