【问题标题】:curl json with cookie returns "‹ŠŽÿÿ)»L"带有 cookie 的 curl json 返回“‹ŠŽÿÿ)»L”
【发布时间】:2016-06-12 14:52:45
【问题描述】:

我正在尝试获取此 json 的内容:http://steamcommunity.com/market/pricehistory/?country=DE&currency=3&appid=730&market_hash_name=Chroma%20Case

这是我的代码:

$url = "http://steamcommunity.com/market/pricehistory/?country=DE&currency=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。谢谢!这真的成​​功了! :)

标签: php json curl cookies


【解决方案1】:

添加curl_setopt($ch, CURLOPT_ENCODING,""); 成功了:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-25
    • 2016-06-05
    • 1970-01-01
    • 2016-11-11
    • 2017-07-14
    • 2019-11-23
    相关资源
    最近更新 更多