1

Angular -cli 6 using HttpClient and HttpHeaders.

My code is as follows:

public getData(params: any): Observable<any> {
   let httpHeaders = new HttpHeaders({'Authorization': 'Bearer xxx'});
   httpHeaders.append('x-auth-token', '');

   return this.http.get('host', {headers: httpHeaders})
   .pipe(
      map(response => {
         return response;
      })
   );
}

How do I access the X-Auth-Token from a response header? In the developer tool, I see

X-Auth-Token: 23e0bef4-8c77-4554-ad1a-1ec4ae134f86

I did see the mentioned possible duplicate question but making the proposed changes

'observe': 'response',
            'x-auth-token': ''

I still fail to see the response headers.

reza
  • 5,972
  • 15
  • 84
  • 126
  • 2
    Possible duplicate of [Angular 4.3.3 HttpClient : How get value from the header of a response?](https://stackoverflow.com/questions/45505619/angular-4-3-3-httpclient-how-get-value-from-the-header-of-a-response) – user184994 Jun 17 '18 at 20:46
  • I did implement the proposed changes to no avail – reza Jun 17 '18 at 21:47
  • Have you exposed the X-Auth-Token by putting it in Access-Control-Expose-Headers in server?Not all headers can be accessed in javascript. – Krishnanunni Jeevan Jun 17 '18 at 23:31
  • yes and that did work, thank you – reza Jun 18 '18 at 17:52

0 Answers0