express - 如何设置我在邮递员中发送的请求标头,但在导航器中?
问题描述
在邮递员中,您可以放置或设置标题。但是我如何设置它,但在导航器中,它会随着时间的推移通过对不同路线的请求而持续?
我已经尝试使用不同的方法从后端设置标题,但两者都不起作用:
res.header('x-token', jwt)
或者喜欢
res.set('x-token', jwt)
从前端我已经尝试过这种方法,但它也不起作用:
const data = {id_token};
let myHeaders = new Headers();
fetch(url, {
method: 'POST',
body: JSON.stringify(data),
headers:{
'Content-Type': 'application/json'
}
})
.then(resp => resp.json())
.then(({jwt}) => {
if (jwt) {
//None of both worked
//myHeaders.append('x-token', jwt);
//myHeaders.set('x-token', jwt);
}
})
.catch(error => console.error('Error:', error))
这是我想发送到不同路线的标题
解决方案
推荐阅读
- python - 按字典键值对过滤熊猫数据框
- google-apps-script - Google Apps 脚本 OAuth1 错误
- android - 项目单击执行方法上的导航抽屉
- python - 我如何获得写入输入所需的时间
- mongodb - 哪个 NoSQL DB 可用于多字段搜索
- reactjs - 如何使用 Jest 和 Native 测试库正确测试 React Native Modals
- node.js - 403 禁止在 Node.js 中使用 sendgrid 发送电子邮件
- spring-webflux - TcpClient 仅在 Spring WebFlux 控制器中返回第一个结果
- python - 在 numpy 数组中查找等值索引
- html - CSS 不允许将 div 的元素拆分到新行