0

I am making a GET request in my react native app. My code is:

const config = {
  headers: {
    Authorization: `Bearer ${authToken}`,
  },
};
axios.get(url, config);

The authorization token is not being sent along with the request. How do I send it?

khateeb
  • 5,265
  • 15
  • 58
  • 114

2 Answers2

0

You could use the same GET method in two ways.

Method 1

axios.get(your_url, {
 headers: {
   Authorization: 'Bearer ' + your_token
 }
})

Method 2

axios({
  method: 'get', 
  url: your_url,
  headers: {
    Authorization: 'Bearer ' + your_token
  }
})

For POST method

axios({
      method: 'post', 
      url: your_url,
      data: { "user_id": 1 }
      headers: {
        Authorization: 'Bearer ' + your_token
      }
    })

Please try with the any of above method and let me know.

Jeffrey Rajan
  • 4,391
  • 4
  • 27
  • 37
0

try this:

var req = {
            url: the url ,
            method: "get",
            headers: {
                Authorization: "Bearer " + val,
                Accept: "application/json"
            }
        };

        axios(req)
            .then(response=>{console.log(response)})
            .catch(error => {});
    });