Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Axios - Remove headers Authorization in 1 call only

Tags:

axios

vuejs2

vuex

People also ask

How do you pass authorization header in Axios POST request?

When you are using the Axios library and to pass custom headers, you need to construct headers as an object with the key name 'headers'. The 'headers' key should contain an object, here it is Content-Type and Authorization .


Try the following

delete axios.defaults.headers.common["Authorization"];
// or which ever header you have to remove

To send a request without:

  • Modifying global axios defaults
  • Creating a new axios instance

Change your request similarly to this:

axios.get('http://example.com', {transformRequest: (data, headers) => {
    delete headers.common['Authorization'];
    return data;
  }
});

The answer I was looking for was posted in the comments of Apurva jain's answer, but hasn't been made an individual answer, so I've posted it separately for easy reference :)


if you already have a default 'Authorization' for all requests you can create an instance for that specific request

var instance = axios.create();
delete instance.defaults.headers.common['Authorization'];

instance.get("http://api.com");


delete axios.defaults.headers.common["Authorization"]; will solve the problem. But remember to add the authorization header back.


I got the same issue trying to query S3 with my web-service auth token. Fixed it with this.

axios.get("http://api.com", {
        headers:{ Authorization:""}
});

You can change the default headers to an empty string, this won't affect the common default headers. Though not entirely sure if all web services will ignore the empty string header.


delete request.defaults.headers.common.Authorization

That request should be return of a $axios.create()