【问题标题】:How to access headers如何访问标题
【发布时间】:2019-09-11 07:07:25
【问题描述】:

此应用程序有一个外部身份验证过程,在从外部系统成功验证用户身份后,用户将被重定向到带有标头值的我的应用程序,因此如何在 angular8 应用程序中读取这些标头值。

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

【问题讨论】:

    标签: javascript angular http-headers


    【解决方案1】:

    这就是你缺少的部分=> , {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?

    【讨论】:

    • 感谢您的及时回复,它转发到我的应用程序,标题我没有生成任何中间 Http 请求。最初,转发到作为唯一请求的代理服务器。
    • 这是一个隐藏的标题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-08
    • 1970-01-01
    • 2016-07-10
    • 2013-05-09
    • 2013-05-18
    • 2021-09-04
    • 1970-01-01
    相关资源
    最近更新 更多