首页 > 解决方案 > 如何设置我在邮递员中发送的请求标头,但在导航器中?

问题描述

在邮递员中,您可以放置​​或设置标题。但是我如何设置它,但在导航器中,它会随着时间的推移通过对不同路线的请求而持续?

我已经尝试使用不同的方法从后端设置标题,但两者都不起作用:

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))

这是我想发送到不同路线的标题

https://i.stack.imgur.com/ueoxu.png

标签: expressrequestheaderjwtpostman

解决方案


推荐阅读