【问题标题】:How get the header of the first http request when I launch an angular app (http://localhost:4200/)启动 Angular 应用程序 (http://localhost:4200/) 时如何获取第一个 http 请求的标头
【发布时间】:2019-11-03 12:31:51
【问题描述】:

我正在寻找第一个 http 请求的标头 http://localhost:4200/

要启动我的应用程序,我会转到 url http://localhost:4200/,我想在控制台中写入 http 输入的标头。

有谁知道这是否可行?

我尝试使用拦截器,但我只拦截我的应用程序的 http 请求和响应排序。

【问题讨论】:

  • 为什么需要http Header?
  • 有什么更新吗?您知道如何获取第一个请求标头了吗?
  • 您找到解决方案了吗?我猜这根本不可能
  • 我不敢相信只有 4 个人需要这个功能...

标签: angular http header angular-http-interceptors


【解决方案1】:

默认情况下,Angular HttpClient 只观察结果,您可以使用 {observe: 'response'} 获取完整响应并从中获取标头。

 this.http.get('/', { observe: 'response' }).subscribe(response => {
    console.log(response.headers.get('SAMPLEITEM'))
 });

记录在案的here

【讨论】:

  • 实际上你在这里给自己打电话,希望标题响应不会改变..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-20
  • 2021-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多