【问题标题】:Fetch restful api获取restful api
【发布时间】:2022-01-28 04:47:56
【问题描述】:

使用 Nodejs 获取 API 的语法是什么,我正在尝试 fetch 但它说 fetch 未定义enter image description here

【问题讨论】:

  • 节点没有 fetch,你必须使用像 node-fetch 这样的 polyfill。
  • 谢谢我真的很感激这个

标签: node.js express pug


【解决方案1】:

nodejs 中不存在 Fetch。为此,您必须使用一些模块来发出获取请求。

一个例子是:https://www.npmjs.com/package/node-fetch

npm install node-fetch

const fetch = require('node-fetch');

const response = await fetch('https://httpbin.org/post', {method: 'POST', body: 'a=1'});
const data = await response.json();

【讨论】:

    猜你喜欢
    • 2018-08-24
    • 1970-01-01
    • 1970-01-01
    • 2020-05-31
    • 1970-01-01
    • 2020-09-12
    • 1970-01-01
    • 2023-01-25
    • 2020-02-26
    相关资源
    最近更新 更多