如何从 Angular 2 响应中获取所有标头? [英] How to get all the headers from an Angular 2 response?

查看:27
本文介绍了如何从 Angular 2 响应中获取所有标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Chrome 开发工具中看到的响应标头与 Angular 2 在 Chrome 控制台中显示的标头不匹配.

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

执行后仅显示 Content-Type 标头:

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

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

推荐答案

默认情况下(对 Javascript)仅公开特定的安全"标头列表.这是出于安全原因.这份名单如下

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

  • 缓存控制
  • 内容语言
  • 内容类型
  • 过期
  • 最后修改时间
  • 语用

为了暴露其他头,服务器应该发送访问控制头 Access-Control-Expose-Headers,列出所有要暴露的标头.

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

这篇关于如何从 Angular 2 响应中获取所有标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆