我想获取 RESTful API 的“X-Total-Count”响应标头。在尝试获取我的 ngResource 'User' 的查询回调函数中的标头时,似乎 $http 忽略了很多响应标头。
这些是我的请求的响应标头:
Access-Control-Allow-Origin: *
Cache-Control: max-age=0, private, must-revalidate
Connection: close
Content-Encoding: gzip
Content-Type: application/json; charset=utf-8
Date: Fri, 17 Oct 2014 11:13:26 GMT
Link: <http://xxxx.xxx/user?page=2>; rel="next"
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Total-Count: 32
在这里,我正在查询一组用户:
User.query({
page: $scope.pagingOptions.currentPage,
limit: $scope.pagingOptions.pageSize
}, function(users, responseHeaders) {
console.log(responseHeaders());
console.log(responseHeaders('X-Total-Count'));
});
这是控制台的结果:
Object { cache-control="max-age=0, private, must-revalidate", content-type="application/json; charset=utf-8"}
null
那么为什么 $http 的 responseHeaders() 函数只转换 10 个标头属性中的 2 个呢?