-1

I am trying to access the headers in the response of a HttpClient post request (also Put request), but it shows undefined. It works perfectly with a get response though.

httpClient.post("url", {observe:"response"}). subscribe(response => { console.log(response.headers); // undefined

console.log(response.headers.get("header-name")); // error });

  • Please give a [mcve]. Are you following the guidance in [the docs](https://angular.io/guide/http#reading-the-full-response)? – jonrsharpe Jan 08 '19 at 18:23
  • Possible duplicate of [#45505619](https://stackoverflow.com/questions/45505619/angular-4-3-3-httpclient-how-get-value-from-the-header-of-a-response) – Harun Yilmaz Jan 08 '19 at 18:34
  • I am not trying to send headers but use one I received from the server. – user8166057 Jan 08 '19 at 18:50

2 Answers2

0

Try this

httpClient.post("url", {observe:"response"}).
pipe(map(response => { 
console.log(response.headers.get('nameofheader'))
}));
MSWA
  • 37
  • 1
  • 11
0

I tried this and it works.

httpClient.request("POST", "url", {observe:"response"}). subscribe(response => { console.log(response.headers.get("header-name")); // OK });