I am trying to do a simple get request via angular2 http like this: (the token is present also retrieved from a post to my api)
let idToken = localStorage.getItem('id_token');
let authHeader = new Headers();
if (idToken) {
authHeader.append('Authorization', 'Bearer ' + idToken);
}
return this._http.get('http://someapicall-to-my-custom-api', {headers: authHeader})
.map(response => response.json())
.subscribe(
data => console.log(data),
error => console.log(JSON.stringify(error)),
() => console.log('Completed')
);
If i call my api without the headers it returns a good result. The moment i add the header i only runs through the error in subscribe. The problem is that i need to start sending the header with it to get some protected data and so far that is failing.
In the console i see no usefull information at all i just see this:
{"_body":{"isTrusted":true},"status":200,"ok":true,"statusText":"Ok","headers":{},"type":3,"url":null}
On the GET request to the api i see no 200 ok but i do when i didnt add the headers. Also there are no response headers.
If i try to use postman to do the same, it works without problems in that program.
I hope someone can point me into the right direction. Could it be my api? How can i debug this?