在Angular 2中读取自定义HTTP响应标头 [英] Reading Custom HTTP response headers in Angular 2
问题描述
在我的angular 2应用程序中,我向服务(HTTPS)发出了HTTP POST请求,服务返回了HTTP响应有一个自定义RESPONSE标头"X-COUNT",但是在下面的代码中,console.log不会打印有关自定义标头"X-COUNT"的信息,但它会打印有关其他标题的信息.
In my angular 2 application , I am making a HTTP POST request to a service(HTTPS) , the HTTP response returned by service has a custom RESPONSE header "X-COUNT", but in below code the console.log does not print info about custom header "X-COUNT" , but it does print info about other headers.
this._http.post(restUri, postdata, options)
.map(itemsResult =>
{
console.log(JSON.stringify(itemsResult.headers));
return items;
}).catch((err) => {
return Observable.of([]);
});
任何想法为什么我无法获得自定义标题信息.
Any idea why I am not able to get custom header info.
推荐答案
由于不允许从客户端访问所有标头,因此需要从服务器端公开"X-COUNT"标头."access-control-expose-header"用于该目的.
Since not all headers are allowed to be accessed from client side, You need to expose the "X-COUNT" header from the server side. "access-control-expose-headers" is used for that purpose.
希望这会有所帮助.
这篇关于在Angular 2中读取自定义HTTP响应标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!