angular - HttpClient 未返回所有响应标头
问题描述
我同意这是一个重复的问题,但我已经尝试过其他帖子中给出的答案,但这不起作用,所以我用我的代码发布我的
我有一种情况,我正在使用自定义标头进行 GET 调用,并且响应还包含自定义标头。使用 HttpClient 获得的响应仅包含 4 个标头,但不包含从我的服务器发送的自定义标头。我可以在 chome 的开发工具的网络选项卡中看到自定义标题。下面是我正在使用的代码
doGetFullResponse(path: string, headerExtra: any) {
let headers = new HttpHeaders();
let authData = localStorage.getItem("user");
if(authData) {
headers = headers.append('Authorization', "BEARER "+authData);
if(headerExtra) {
for(let key in headerExtra)
headers[key] = headerExtra[key];
}
//httpClient is HttpClient from '@angular/common/http'
return this.httpClient.get(path, {headers: headers, observe: "response"});
}
else {
this.router.navigateByUrl("/");
}
}
我称这个函数为
this.httpservice.doGetFullResponse().subscribe((res)=>{
//this.pointAudits = res.json();
res.headers.keys().map((key)=>console.log(key+":"+res.headers.get(key)));
})
下面是输出:
pragma:no-cache content-type:application/json;charset=UTF-8 cache-control:no-cache, no-store, max-age=0, must-revalidate expires:0
从我的服务器“ MAX_ITEM_COUNT
”发送的自定义标头不会出现在此处。有什么我想念的吗?我正在使用 Angular 4。如果需要任何细节,请告诉我。
解决方案
推荐阅读
- amazon-web-services - 如何验证第三方 JWT 令牌
- python - 使用 Python 'in' 运算符检查 Dataframe 列值是否在字符串列表中会导致 ValueError
- ios - MobileVLCKit 在播放 FB Live Video 时总是停止
- javascript - 输入焦点时键盘消失 - 移动
- postgresql - 如何更新我的所有条目?
- react-native - 有没有办法限制在调用 URL 的响应中返回的 Web 数据量?
- flutter - 我对 sqlite 的更新不是持久的(更改页面后)
- ruby-on-rails - UserMailer:Class 的未定义方法“email_verification”
- c# - 如何在 xamarin 表单中使用 yyy 写入特征时修复异常设备 xxx 断开连接?
- python - Pivot Pandas 列表的列