【发布时间】:2017-02-16 09:46:32
【问题描述】:
restservice 在 get 请求中提供标头信息。如何通过响应访问它们?
我只在回复中得到这些标题信息:
Array[3]
0:{"content-type" => Array[1]}
1:{"access-control-allow-origin" => Array[1]}
2:{"access-control-allow-credentials" => Array[1]}
// Angular request
this._http.get("http://anyUrl/restservice/list")
.map((response:Response) => {
console.log(response);//<-- gives the above information but nothing more
return response.json();
});
【问题讨论】:
-
在您的
map()中,尝试阅读response.headers而不是response.json()。 -
如果您在
response对象中看不到您要查找的内容,这可能意味着它一开始就不存在(即服务器没有设置您想要的标头)。我认为 Angular 在将响应交给您之前不会对其进行清理。尝试使用Postman 运行相同的请求,看看是否得到不同的标头。 -
我可以在 chrome 开发工具中看到标头比响应中的标头多。也许 .map 操作会进行任何类型的过滤?
-
我无法重现它:获取所有标题作为响应。你的最终目标是什么,得到一些特定的标题?
-
奇怪...在您的示例中,您在
map()之前登录没有任何作用,所以不是这样。你确定console.log(response.headers)时只看到3个成员吗?