How to add extra header to post request with vue-resource?
Ok, I think I figured it out. Thanks to comment by @ssc-hrep3 and answer by @ittus
let headers = {
'Content-Type': 'application/json;charset=utf-8'
};
if(token !== '') {
headers['TOKEN'] = token
}
return this.http.post(uri, data, {headers: headers})
.then(this.extractData)
.catch(this.handleError);
In document, headers
should be normal Javascript object, not window.Headers
Please try
let headers = {
'Content-Type': 'application/json;charset=utf-8'
};
if(token !== '') {
headers['TOKEN'] = token
}
return this.http.post(uri, data, {headers})
.then(this.extractData)
.catch(this.handleError);