【问题标题】:Different answers to the same queries cUrl (Steam Market)相同查询的不同答案 cUrl (Steam Market)
【发布时间】:2015-08-02 15:30:13
【问题描述】:

当您在浏览器中点击链接时:

http://steamcommunity.com/market/priceoverview/?country=US%C2%A4cy=5&appid=570&market_hash_name=Gem%20of%20Taegeuk

给出 { "success": false },在标题 500 中出现错误。但是当我通过 cUrl 进行同样的查询时

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://steamcommunity.com/market/priceoverview/?country=US&currency=5&appid=570&market_hash_name=Gem%20of%20Taegeuk");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);   
$curl = curl_exec($ch);

作为回应,我得到的不是 json:

‹ЄV*.MNN-.VІJKМ)NяятКC4

告诉我如何解决这个问题以及错误 (500) 的原因可能是什么?

【问题讨论】:

    标签: php curl steam steam-web-api


    【解决方案1】:

    服务器返回压缩后的响应(标头Content-Encoding: gzip)。所以,你需要自动编码:

    curl_setopt($ch,CURLOPT_ENCODING, '');

    附:与curl 不同的浏览器会自动解包响应。

    【讨论】:

      【解决方案2】:

      两个问题:

      1) 在示例链接中,country=US 之后还有一个 %C2%A4cy% 和缺少的 curren。 CURL 中的 URL 看起来没问题。

      2) 你的 CURL 命令不跟随重定向,URL 应该是https://(浏览器会自动这样做)。您可以使用 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 跟踪重定向

      【讨论】:

        猜你喜欢
        • 2022-12-17
        • 1970-01-01
        • 2013-07-19
        • 1970-01-01
        • 2017-09-19
        • 2015-05-18
        • 1970-01-01
        • 2021-11-14
        • 2015-06-30
        相关资源
        最近更新 更多