2010-07-17 28 views
2

如果我在瀏覽器中鍵入(見https://stackapps.com/questions/2/getting-started-with-the-api):爲什麼rebol失敗與stackoverflow api?

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

返回

{ 
    "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" 
     } 
     } 
    } 
    ] 
} 

如果我在REBOL控制檯輸入:

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

它返回一些w eird二進制字符。

回答

3
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" 
     } 
     } 
    } 
    ] 
} 
+0

哇,你是一個genious :) – 2010-07-18 07:30:13

2

REBOL忽略了Content-Encoding: gzip響應標題,無論您在Accept-Encoding:標題中放入了什麼,該stackoverflow似乎都是堅決使用的。在Unix上,wget和捲曲有同樣的問題,但我可以做到這一點,看看預期的內容:

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

確實REBOL有辦法解壓縮gzip的內容?

+0

我在這裏找到一個lib http://www.rebol.org/view-script.r?script=gunzip。所以我會盡力謝謝。 – 2010-07-17 12:11:33

1

基於http://www.mail-archive.com/[email protected]/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, 
.... 

幾乎工程:) 這樣的核心代碼都在那裏,只是沒有適當曝光......這的確是一個遺憾......

但計算器是不是很好要麼沒有投訴的http規格,並忽略了接受編碼頭...

+0

我會報告給api,但由於我不是專家,我應該如何制定這個精確的? – 2010-07-18 07:31:07

+2

「無論Accept-Encoding HTTP頭的存在和值如何,API服務器都會返回gzip內容。請尊重它,以避免混淆,並允許更輕鬆的實驗。」 - 類似的東西 – onetom 2010-07-18 15:06:21