Currently, I am working with Angular2 and dotcms. My goal is to retrieve response headers after making a call to subscribe.
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
.append('Access-Control-Expose-Headers', 'X-Custom-header')
};
let json = {..};
let apiURL = 'api/content/publish.1'
this.http.put(apiURL, JSON.stringify(json), httpOptions).subscribe((res:Response) => console.log(res.headers.keys()));
Although the response body appears empty, when checking in Chrome, all response headers are visible
HTTP/1.1 200 OK
X-Powered-By: Express
access-control-allow-origin: *
server: Apache-Coyote/1.1
location: http://localhost:3000/api/content/inode/bb23a6ac-f6f0-4ed3-8971-095dbc38ef52
inode: bb23a6ac-f6f0-4ed3-8971-095dbc38ef52
identifier: c05e9b20-46a4-4efc-9ded-b5d1a2613cad
access-control-allow-methods: GET, HEAD, POST, PUT, DELETE, OPTIONS
access-control-allow-headers: Authorization, Accept, Content-Type,
Cookies
content-length: 0
date: Thu, 15 Feb 2018 12:34:27 GMT
connection: close
Even though I received a status code of 200 and execution was successful, I am unable to retrieve the response headers
ERROR TypeError: Cannot read property 'headers' of null