简体   繁体   中英

How to get all the headers from an Angular 2 response?

Chrome Dev Tools中的响应

The response headers I see in Chrome Dev tools don't match the ones that Angular 2 is showing in the Chrome console.

仅显示内容类型

Only the Content-Type header is showing up after having executed:

this.http.get(tempUrl).map(res=>{
      console.log("csrf received");
      console.log(res);
})

Only a certain list of "safe" headers are exposed by default (to Javascript). This is for security reasons. This list is as follows

  • Cache-Control
  • Content-Language
  • Content-Type
  • Expires
  • Last-Modified
  • Pragma

In order to expose other headers, the server should send the access control header Access-Control-Expose-Headers , listing all the headers it wants to expose.

Access-Control-Expose-Headers: Content-Length, X-CSRF-Token

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM