I'm using Angular 4.4.4 and I need to set the Authorization
header for a GET request. I've studied the docs and the code to figure out how to do this. This was the result:
const headers = new Headers({ Authorization: this.auth.accessToken});
this.http.get('/api/Messages', { headers } as RequestOptionsArgs)
However, this doesn't work. The request is made without the header option.
But if I do it as follows
const options = { headers: {Authorization: this.auth.accessToken} as any};
return this.http.get('/api/Messages', options as RequestOptionsArgs)
It works.
But I would expect the first attempt to work too. Can someone explain to me what is wrong with my first attempt or explain to me what the correct approach is?