Hey guys
This is how I set my headers. I looked all over the internet but when I send it to the server it doesn’t recognize my Authorization header. How did you solve that problem?
createHeaders(headers:Headers) {
this.storage.getItem('token')
.then(
(token) => { console.log('Bearer ' + token);
headers.append('Authorization', 'Bearer ' + token);
},
(error) => console.error(error)
);
headers.append('AllowEntry', btoa(this.allow_entry));
headers.append('Content-Type', 'application/json');
}
/**
* Post data to sevrer
* @param any postData Data to post to the server
* @param string url Url to post to
*/
post(postData, url)
{
var headers = new Headers();
this.createHeaders(headers);
headers.set('Authorization', 'Bearer my-token');
let options = new RequestOptions({ headers: headers });
return this.http.post(ApiSettings.API_ENDPOINT+url, postData, options)
.toPromise()
.then(response => response.json())
.catch(this.handleError);
}