您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Angular 4.3.3 HttpClient:如何从响应的标头获取值?

Angular 4.3.3 HttpClient:如何从响应的标头获取值?

您可以观察到完整的响应,而不仅仅是内容。为此,您必须传递observe: responseoptions函数调用的参数中。

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);
  });
其他 2022/1/1 18:22:39 有373人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶