如何使用 Angular 5 HttpClient 读取完整响应 header

How to Reading the full response header using Angular 5 HttpClient

我在 Angular 5 中编写了服务,它使用 HttpClient class 向我的后端发出 GET 请求。

我的请求是这样的:

headers =  new HttpHeaders().set('Content-Type', 'application/json')
                             .set('X-XSRF-TOKEN', 'sdfhjsdgh');

          const options = ({ headers: headers});
          this.http.get('http://127.0.0.1:8080/api/v1/display', options)
         .filter(data => data.status === 200 || data.status === 206)
         .map((res) => this.success(res))
         .catch((res) => this.failure(res, service));

如何使用响应 header?这样我就可以检查状态代码等等。

非常感谢任何帮助。

headers =  new HttpHeaders().set('Content-Type', 'application/json')
                         .set('X-XSRF-TOKEN', 'sdfhjsdgh');

      this.http.get('http://127.0.0.1:8080/api/v1/display', {
        headers: headers,
        params: params,
        observe: 'response'})
     .filter(data => data.status === 200 || data.status === 206)
     .map((res) => this.success(res))
     .catch((res) => this.failure(res, service));