角度2:无法访问http请求中的响应标头 [英] Angular 2: Can't access response headers in a http request
问题描述
我正在使用angular2-http(alpha.44)模块从REST Api中检索数据.我无法弄清楚如何访问响应的标题映射中的信息,我需要从中获取一个特定字段.示例:
I'm using angular2-http(alpha.44) module to retrieve data from a REST Api. I can't figure out how to access the information that comes in the headers map of the response, from which I need a specific field. Example:
var req = new Request({
url: `localhost/api/products`,
method: RequestMethods.Get
});
this.http.request(req).subscribe(
res => {
// Can't access the headers of the response here.... res.headers is empty
},
error => { ... },
_ => {}
);
奇怪的是,如果我在浏览器的开发工具中检查网络流量,则会显示响应标头...
Strangely enough, if I check the network traffic in the browser's dev tools, the response headers are present...
推荐答案
在github上已经存在有关该问题的问题:-
There is already an issue about that problem opened on github:-
https://github.com/angular/angular/issues/5237 #issuecomment-156059284
请检查它,因为有人发布了解决方法.
Please check it, as someone posted a workaround.
更新
角度小组已经解决了这个问题.
The angular team has already solved this problem.
这篇关于角度2:无法访问http请求中的响应标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!