我最近在学习Angular。 我有一个分页请求。
const myParams = new HttpParams().set('page', page.toString()).set('size', size.toString());
this.http.get<HttpResponse<User[]>>('https://localhost:8443/user/', {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
params: myParams,
observe: 'response'
}).suscribe((response: HttpResponse<User[]>) => this.data = response.body);
数据库中元素的总数通过 X-Total-Count
头信息传递给客户端。我试图这样读取它:
.suscribe((response: HttpResponse<User[]>) => {
this.data = response.body;
this.totalCount = response.headers.get('X-Total-Count');
});
但是这并不起作用。结果发现response.headers仅包含真实http响应头的一个子集。
这就是headers对象的样子。
"headers": {
"normalizedNames": {},
"lazyUpdate": null
}
我确信 X-Total-Count 已经发送。Firefox 开发者工具可以显示它。请问如何将其包含在响应中?
更新
这个问题与被识别为重复的问题不同,区别在于:我并没有询问如何检查完整的httpResponse。我自己解决了这个问题。我一直在问的是为什么Response
的headers
属性不完整。
observe: 'response'
。我的问题是,response.headers
并没有包含后端发送的所有标头。 - Mr.H.