javascript - 如何访问 header

标签 javascript angular http-headers

该应用程序有一个外部身份验证过程,在从外部系统成功验证用户身份后,用户将被重定向到我的应用程序,并带有 header 值,那么如何在 Angular8 应用程序中读取这些 header 值。

在应用程序模块和应用程序组件承包商方法中使用了 HttpClientModule,但没有成功,并在所述类中使用了 HttpHeaders

最佳答案

这就是你缺少的部分=> , {observe: 'response'}

http
  .get<MyJsonData>('/data.json', {observe: 'response'})
  .subscribe(resp => {
    // Here, resp is of type HttpResponse<MyJsonData>.
    // You can inspect its headers:
    console.log(resp.headers.get('X-Custom-Header'));
    // And access the body directly, which is typed as MyJsonData as requested.
    console.log(resp.body.someField);
  });

Angular 4.3.3 HttpClient : How get value from the header of a response?

关于javascript - 如何访问 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57883828/

相关文章:

javascript - 在 Bind 而不是 Click 上执行的函数

javascript - 在 div 中显示 json html 数据

javascript - 基于 observable,从 observable 对象中选择 observable

angular - 如何从 API 响应接收类型为 csv 的文件

javascript - 保存菜单当前位置

angular - 空合并运算符 Angular 2

angular - 不允许加载 Electron 中的本地资源错误- Angular v7.0.1

python - 如何使用 Uber API 的个人访问 token ? (获取 'No authentication provided.' )

node.js - s3.getSignedUrl ResponseContentDisposition 参数不起作用

ruby-on-rails - Engine Yard Rails 应用程序 - 在 Elastic Load Balancer (ELB) 处终止 SSL 并传递 X-Forwarded-Proto http header