javascript - 如何在 node js 中为 route.get 设置标头和参数?
问题描述
如何在 node js 中为 route.get 设置标头和参数?我想将标头值和参数设置为 API 数据调用 URL。
router.get("/getdata", async (req, res) => {
res.header({
'key': '123456'
});
await fetch(`https://example.com/api?param=${data}`)
.then((data) => data.json())
.then((data) => res.json({ msg: data }))
.catch((err) => console.log(err));
});
我的问题是如何在 node js 中的 router.get 中设置标头和参数数据?
解决方案
阅读有关路由的 Express文档。它解释了如何使用例如req.query
访问该param
获取 URL 中的内容。
推荐阅读
- basic - 神秘的编译(BASIC?)遗留程序
- apache-spark - pyspark如何使用两列编写UDF
- .net - 有没有办法获取使用 Azure SDK for .NET 部署的 ARM 模板的输出参数?
- alfresco - Alfresco share dashlet:如何为所有用户设置唯一的 componentId
- git - 如何在不重复避免变基的情况下挑选提交?
- c# - 如何在 JSON 中创建数组?
- google-api - 无法从 App Center 连接到 Google Play 以分发 App
- c++ - C ++通过结构数组搜索值
- firebase - Firebase 云功能最佳实践?
- javascript - 为什么在弗雷德弗林斯顿之后警报显示未定义?ES6 中的“const”有哪些属性?