Search code examples
angularangular-httpclient

Why I get only two headers in Angular using HttpClient?


I'm trying to get all headers from the response to a post method:

this.http.post<User>(this.url, user, {
        observe: 'response',
        responseType: 'json',
      })
      .subscribe((res) => {
        console.log('Headers: ' + JSON.stringify(res.headers));
      });
}

earlier:

url = 'http://localhost:8080/user/login';
constructor(private http: HttpClient) {}

I followed most tutorials and stackoverflow answers, but I get only two headers: Headers: {"normalizedNames":{},"lazyUpdate":null}

When I tried with postman and curl everything works fine, that is I get all the headers, but not in Angular (I'm using version Angular CLI: 15.2.8)


Solution

  • Check this one - Angular HttpClient missing response headers

    In your case seems that second answer might help you, about headers being lazy loaded