我正在尝试获取API发送的自定义标头的值,但是我无法使用有角度的httpclient来获取标头的值
以下是我使用的示例代码
getUsers(pageNumber? , pageSize?): Observable<PaginatedResult<IUser[]>> {
const paginatedResult: PaginatedResult<IUser[]> = new PaginatedResult<IUser[]>();
let params: HttpParams = new HttpParams();
if (pageNumber != null) {
params = params.append('pageNumber', pageNumber);
}
if (pageSize != null) {
params = params.append('pageSize', pageSize);
}
return this.httpClient.get<IUser[]>(this.baseUrl + 'users', {observe: 'response', params: params})
.pipe(
map(response => {
paginatedResult.result = response.body;
if (response.headers.get('Pagination') != null) {
paginatedResult.paginationInfo = JSON.parse(response.headers.get('Pagination'));
}
return paginatedResult;
})
);
}
尽管“ Pagination”标头被标记为“ Access-Control-Expose-Header”,但“(response.headers.get('Pagination')”这一行始终返回null
如以下屏幕截图
所示: