I am consuming an API through a post method and need to send in the Authorization header. I'm doing the following:
public post(resource, body, authorization = false): Observable<any> {
const headers = new HttpHeaders();
headers.append('Content-Type', 'application/json');
headers.append('Accept', 'application/json');
if (authorization) {
let token = this.userStorageService.get('accessToken');
headers.append('Authorization', 'Bearer ' + token);
}
return this.http
.post<Observable<any>>('${environment.apiUrl}${resource}', JSON.stringify(body), {headers: headers})
.map(response => response);
}
But for some reason the Angular does not send the headers. I've tried different ways, but none works. Anyone have any idea what that might be?
OBS 1: I'm using Angular 5 and Ionic 3 OBS 2: I've tried using Interceptors and it did not work NOTE: I have already debugged the request in the api by Postman, it works right there, sending the headers and everything, but the app does not work in any way.