Sending the bearer token with axios

前端 未结 9 1360
野趣味
野趣味 2020-11-28 21:21

In my react app i am using axios to perform the REST api requests.

But it\'s unable to send the Authorization header with the request.

Here is my co

9条回答
  •  余生分开走
    2020-11-28 22:02

    If you want to some data after passing token in header so that try this code

    const api = 'your api'; 
    const token = JSON.parse(sessionStorage.getItem('data'));
    const token = user.data.id; /*take only token and save in token variable*/
    axios.get(api , { headers: {"Authorization" : `Bearer ${token}`} })
    .then(res => {
    console.log(res.data);
    .catch((error) => {
      console.log(error)
    });
    

提交回复
热议问题