question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to See Authorization Header that set by Axios?

See original GitHub issue

Hi

How can I see what is actually being sent by axios. I set my authorization header but I cannot see what is being sent to the server. I checked FF and Chrome but I see nothing regarding authorization headers.

Is there away I can print it out?

export const axiosInstance = axios.create({
  baseURL: getBaseUrl(),
  timeout: 5000,
  contentType: 'application/json',
  Authorization: 'Bearer 14154151'
});

“axios”: “^0.18.0”,

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

5reactions
gcoxcommented, Aug 30, 2018

You can see the raw headers sent by inspecting the response. Here’s an example using a response interceptor:

axiosInstance.interceptors.response.use(res => {
  console.log(res.request._header)
  return res;
}, error => Promise.reject(error));

However, the problem with your setup is that you’re using Authorization as if it were a config option for axios, which it is not. It is an HTTP header that you need to set. Same problem with contentType. So, you just need to slightly modify your setup like this:

export const axiosInstance = axios.create({
  baseURL: getBaseUrl(),
  timeout: 5000,
  headers: {
    Authorization: 'Bearer 14154151',
    'Content-Type': 'application/json'
  }
});

See the request config section of the readme for a list of all the options.

0reactions
chinesedfancommented, Dec 28, 2019

Closed due to stale.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to send authorization header with axios - Stack Overflow
const header = `Authorization: Bearer ${token}`; return axios.get(URLConstants.USER_URL, { headers: { header } });. Gives me this error:
Read more >
How to send the authorization header using ... - Flavio Copes
To set headers in an Axios POST request, pass a third object to the axios.post() call. You might already be using the second...
Read more >
Using Axios to set request headers - LogRocket Blog
Axios methods such as post() and get() enable us to attach headers to requests by supplying a headers' object as the second parameter...
Read more >
Set the Authorization Header with Axios - Mastering JS
Setting request headers with Axios is easy. Here's how you can set the Authorization header, which is typically used to send access tokens ......
Read more >
How To Set Request Headers Using Axios? - RapidAPI
Your application may have multiple API requests, and you may want to set request headers for all of them. Instead of adding the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found