0

但它总是返回未定义的主体。

这是我的源代码。: 静态变量

const TOKEN = 'xoxp-7186818662-7186899793-7811139362-ccc6df';
const emojiAPIUrl = 'https://slack.com/api/emoji.list';

:使用

module.exports = function (robot) {
    robot.hear(/show emoji/igm, function(msg){
        var paramData = {'token' : TOKEN};
        var result = robot.http(emojiAPIUrl)
                        .headers({'X-Requested-With': 'XMLHttpRequest', 'Content-Type': 'application/x-www-form-urlencoded'})
                        .post(paramData, function(error, res, body){
                            console.log('err >> ' + error);
                            console.log('res >> ' + stringifyObject(res));
                            console.log('body >> ' + body);
                        });
    });
};

以下是我得到的结果。

2015-07-19T06:22:27.303867+00:00 app[web.1]: err >> Error: socket hang up
2015-07-19T06:22:27.303960+00:00 app[web.1]: res >> 
2015-07-19T06:22:27.304014+00:00 app[web.1]: body >> undefined

您可以通过调用以下网址来检查结果

https://slack.com/api/emoji.list?token=xoxp-7186818662-7186899793-7811139362-ccc6df

我不明白为什么不能得到像 url 这样的 json 结果。感谢:D

PS如果你知道hubot scripting guide with javascript,请分享:D。网络上有很多示例,但主要是咖啡脚本很难参考:-<

4

1 回答 1

0

在 URL https://slack.com/api/emoji.list?token=xoxp-7186818662-7186899793-7811139362-ccc6df不是 POST 它是 GET 所以你应该这样做:

robot.http("https://slack.com/api/emoji.list?token=xoxp-7186818662-7186899793-7811139362-ccc6df")
  .get()(function(err, res, body) {
     console.log(body);
  }
);
于 2015-07-19T06:38:30.390 回答