【已解决】cnodejs的开放API访问出错
发布于 3个月前 作者 Jerry-HQG 431 次浏览 来自 问答

Hi Buddies,

我在通过我们的【通用REST数据适配器】访问cnodejs的开放API时出错,得不到数据,但是用浏览器可以打开。 得到的结果是: [2014-10-29 10:55:39.616] [DEBUG] SuperAgentFacade - Received data: <html> <head><title>301 Moved Permanently</title></head>

<body bgcolor="white">

301 Moved Permanently


nginx/1.4.6 (Ubuntu)
</body> </html>

API: https://cnodejs.org/api/v1/topics?mdrender=false

错误信息:

[2014-10-29 10:55:38.651] [DEBUG] proxy - _getFilter query: {} [2014-10-29 10:55:38.652] [DEBUG] proxy - getEntity targetUrl /topics?mdrender=false [2014-10-29 10:55:38.652] [DEBUG] SuperAgentFacade - HTTP protocol is "http:", isSSEnabled is false [2014-10-29 10:55:38.654] [DEBUG] SuperAgentFacade - Set HTTP Request timeout: 90000 [2014-10-29 10:55:38.655] [DEBUG] proxy - getEntity Set Ranger header items=0-9 [2014-10-29 10:55:38.657] [DEBUG] SuperAgentFacade - HTTP OPTIONS: {"method":"GET","hostname":"cnodejs.org","path":"/api/v1/topics?mdrender=false","headers":{"Accept":"application/json","User-Agent":"RapidApps","Content-Type":"application/json","Range":"items=0-9"}} [2014-10-29 10:55:39.606] [DEBUG] SuperAgentFacade - HTTP Response Headers: {"server":"nginx/1.4.6 (Ubuntu)","date":"Wed, 29 Oct 2014 02:55:36 GMT","content-type":"text/html","content-length":"193","connection":"keep-alive","location":"https://cnodejs.org/api/v1/topics?mdrender=false"} [2014-10-29 10:55:39.615] [DEBUG] SuperAgentFacade - HTTP Response Status Code: 301 **[2014-10-29 10:55:39.616] [DEBUG] SuperAgentFacade - Received data: <html> <head><title>301 Moved Permanently</title></head>

<body bgcolor="white">

301 Moved Permanently


nginx/1.4.6 (Ubuntu)
</body> </html>** .... [2014-10-29 10:55:39.617] [DEBUG] collection - get() Failed to retrieve data list: <html> <head><title>301 Moved Permanently</title></head> <body bgcolor="white">

301 Moved Permanently


nginx/1.4.6 (Ubuntu)
</body> </html>

transformTypes: 0ms [2014-10-29 10:55:39.618] [DEBUG] collection - _isFullDataPage start: 0

关于【通用REST数据适配器】: 通用REST数据适配器可以将任何的REST数据转换成我们平台所需要的数据模型(即取得数据列表,不管数据被如何嵌套和封装),并支持过滤查询,分页,缓存。仅需配置adapter的JSON文件,就可以实现转换。 cnode adapter配置示例:

{
    "name": "cnodejs",
    "version": 1.0,
    "description": "CNode community open api",
    "baseurl": "http://cnodejs.org/api/v1",
    "entities": [
        {
            "name": "topics",
            "description": "CNode latest topics",
            "attributes": [
                {
                    "name": "id",
                    "key": "true"
                },
                {
                    "name": "title"
                },
                {
                    "name": "last_reply_at"
                }
            ],
            "mapping": [
                {
                    "verb": "GET",
                    "path": "/topics",
                    "description": "Returning a list of topics.",
                    "target": "/topics?mdrender=false",
                    "datahandler": "$.data.*"
                }
            ],
            "cache": {
                "key": "id"
            }
        }
    ]
}
3 回复

@alsotang cnode API允许这种访问方式吗?

sorry,是我粗心了。 我用的http应该是https。没这个问题了。:-)

回到顶部