I have a number of post requests in my app. Some of them have to have and extrace header with token
I'm not sure how to append it
So far my code is like this. I'm checking if there is a token and when append it to headers and after that I make post request with vue-resource post method.
let headers = new Headers({'Content-Type': 'application/json;charset=utf-8'});
if(token !== '') {
headers.append('TOKEN', token);
}
return this.http.post(uri, data, headers)
.then(this.extractData)
.catch(this.handleError);
But this doesn't append TOKEN
What does work is this
this.http.interceptors.push(function(request) {
request.headers.set('TOKEN', token);
});
at the place of headers.append('TOKEN', token);
But for some reason it pushes TOKEN
header not for certain requests but for all of them
So when I'm make request with token - it works fine, after that I make request witthout token but it is still adds it.
Anyone knows what is the best way to fix this?
UPD If I console.log(headers.get('TOKEN'))
while doing headers.append('TOKEN', token);
it gives me the right value. So my guess is that post request itself is called with wrong headers.
To add custom headers to an HTTP request object, use the AddHeader() method. You can use this method multiple times to add multiple headers. For example: oRequest = RequestBuilder:Build('GET', oURI) :AddHeader('MyCustomHeaderName','MyCustomHeaderValue') :AddHeader('MySecondHeader','MySecondHeaderValue') :Request.
For adding header to the Card , you need to create wrapper div element with e-card-header-caption class. Place the div element with e-card-header-title class inside the header caption for adding main title. Place the div element with e-card-sub-title class inside the header caption element for adding sub-title.
Intercepting a request We are using vue-resource http client package for intercepting requests in vuejs. import Vue from "vue"; import App from "./App. vue"; import VueResource from 'vue-resource'; // telling vue. js to use this package Vue.
Vue.http.headers.common['Authorization'] = "Basic Token";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With