开发者

Why rebol fails with stackoverflow api?

If I type in a browser (see https://stackapps.com/questions/2/getting-started-with-the-api) :

http://api.stackoverflow.com/1.0/stats

it returns

{
  "statistics": [
    {
      "total_questions": 800830,
      "total_unanswered": 131356,
      "total_accepted": 500653,
      "total_answers": 2158752,
      "total_comments": 3125048,
      "total_votes": 7601765,
      "total_badges": 798091,
      "total_users": 289282,
      "questions_per_minute": 1.50,
      "answers_per_minute": 3.12,
      "badges_per_minute": 1.20,
      "views_per_day": 455215.44,
      "api_version": {
        "version": "1.0",
        "revision": "2010.7.17.1"
      },
      "site": {
        "name": "Stack Overflow",
        "logo_url": "http://sstatic.net/stackoverflow/img/logo.png",
        "api_endpoint": "http://api.stackoverflow.com",
        "site_url": "http://stackoverflow.com",
        "description": "Q&A for professional and enthusiast programmers",
        "icon_url": "http://sstatic.net/stackoverflow/apple-touch-icon.png",
        "state": "normal",
        "styling": {
          "link_color": "#0077CC",
          "tag_foreground_color": "#3E6D8E",
          "tag_background_color": "#E0EAF1"
        }
      }
    }
  ]
}

If I type this in rebol console:

read http://api.sta开发者_开发百科ckoverflow.com/1.0/stats

It returns some weird binary chars.


probe load to-string gunzip to-string read/binary http://api.stackoverflow.com/1.0/stats
connecting to: api.stackoverflow.com
{
  "statistics": [
    {
      "total_questions": 801559,
      "total_unanswered": 131473,
      "total_accepted": 501129,
      "total_answers": 2160171,
      "total_comments": 3127759,
      "total_votes": 7607247,
      "total_badges": 798608,
      "total_users": 289555,
      "questions_per_minute": 0.93,
      "answers_per_minute": 1.83,
      "badges_per_minute": 0.73,
      "views_per_day": 455579.60,
      "api_version": {
        "version": "1.0",
        "revision": "2010.7.17.2"
      },
      "site": {
        "name": "Stack Overflow",
        "logo_url": "http://sstatic.net/stackoverflow/img/logo.png",
        "api_endpoint": "http://api.stackoverflow.com",
        "site_url": "http://stackoverflow.com",
        "description": "Q&A for professional and enthusiast programmers",
        "icon_url": "http://sstatic.net/stackoverflow/apple-touch-icon.png",
        "state": "normal",
        "styling": {
          "link_color": "#0077CC",
          "tag_foreground_color": "#3E6D8E",
          "tag_background_color": "#E0EAF1"
        }
      }
    }
  ]
}


REBOL is ignoring the Content-Encoding: gzip response header, which stackoverflow seems adamant to use, regardless of what you put in your Accept-Encoding: header. On Unix, wget and curl have the same problem, but I can do this to see the intended content:

curl http://api.stackoverflow.com/1.0/stats | zcat

Does REBOL have a way to uncompress gzip content?


Based on http://www.mail-archive.com/rebol-bounce@rebol.com/msg03531.html

>> do http://www.rebol.org/download-a-script.r?script-name=gunzip.r
connecting to: www.rebol.org
Script: "gunzip" (30-Dec-2004)
>> print to-string gunzip read http://api.stackoverflow.com/1.0/stats
connecting to: api.stackoverflow.com
{
  "statistics": [
    {
      "total_questions": 801316,
      "total_unanswered": 131450,
      "total_accept���������������������accept������E531450,
      "tocomment312672�vote7605283badge7984187946531450,
  tal_unans_per_minutet.0531450,
....

almost works :) so the core code is all there, just not exposed properly... it's a pity indeed...

but stackoverflow is not nice either not being complaint to the http specs and ignoring the accept-encoding header...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜