在NodeJS中获取和发布文本

Rie*_*elt 1 api fetch node.js

我正在尝试从API中获取文本,该API只返回一串文本((此处))并且在响应中将问题抛出.发布时,它出来了[object Response],并console.log没有显示我想要的文本.

我正在使用的代码:

fetch('http://taskinoz.com/gdq/api').then(
    function(response) {
      console.log(response);
      throttledSendMessage(channel, response);
      return response;
    })
  .catch(function(error) {
    throttledSendMessage(channel, "An error has occured");
  })
Run Code Online (Sandbox Code Playgroud)

可在此处找到日志

谢谢你和我一起找,找不到解决方案:/

Aar*_*ron 6

我认为因为fetch返回一个Response你需要调用其中一个函数Response来获取正文的文本.这是一个例子:

fetch('https://github.com/')
  .then(res => res.text())
  .then(body => console.log(body));
Run Code Online (Sandbox Code Playgroud)