1

In my angular 2 application , I am making a HTTP POST request to a service(HTTPS) , the HTTP response returned by service has a custom RESPONSE header "X-COUNT", but in below code the console.log does not print info about custom header "X-COUNT" , but it does print info about other headers.

this._http.post(restUri, postdata, options)
            .map(itemsResult =>
            { 
                console.log(JSON.stringify(itemsResult.headers));
                return items;
        }).catch((err) => {

            return Observable.of([]);

        }); 

Any idea why I am not able to get custom header info.

refactor
  • 13,954
  • 24
  • 68
  • 103
  • Helpful link https://stackoverflow.com/questions/25673089/why-is-access-control-expose-headers-needed – refactor Jul 06 '17 at 11:30

1 Answers1

3

Since not all headers are allowed to be accessed from client side, You need to expose the "X-COUNT" header from the server side. "access-control-expose-headers" is used for that purpose.

Hope this helps.

Fahad Nisar
  • 1,723
  • 12
  • 18
  • A discussion on this topic: https://github.com/angular/angular/issues/5237. `access-control-expose-headers` description for more read: https://developer.mozilla.org/es/docs/Web/HTTP/Headers/Access-Control-Expose-Headers. – jacekbj Jul 06 '17 at 11:18