【发布时间】:2020-12-10 05:44:15
【问题描述】:
我正在尝试从 API 获取 JSON 数据。我在我的 express 应用程序中使用 node-fetch。如果我输入绝对 URL,我就能够获取数据。但我希望像这样获取在 req.body 中输入的数据
app.post('/data', async(req, res) => {
const url = req.body
const fetchData = await fetch(url)
const data = await fetchData.json()
res.json({data: data})
})
这是我得到UnhandledPromiseRejectionWarning: TypeError: Only absolute URLs are supported的错误
有没有办法做到这一点??
【问题讨论】:
标签: node.js json rest express node-fetch