Sending the bearer token with axios

前端 未结 9 1355
野趣味
野趣味 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 21:52

    const config = {
        headers: { Authorization: `Bearer ${token}` }
    };
    
    const bodyParameters = {
       key: "value"
    };
    
    Axios.post( 
      'http://localhost:8000/api/v1/get_token_payloads',
      bodyParameters,
      config
    ).then(console.log).catch(console.log);
    

    The first parameter is the URL.
    The second is the JSON body that will be sent along your request.
    The third parameter are the headers (among other things). Which is JSON as well.

提交回复
热议问题