简体   繁体   English

Angular8 充满了 HttpClient 响应头

[英]Angular8 get full of HttpClient response headers

I'm using HttpClient to request a json file.我正在使用 HttpClient 请求一个json文件。 I want the file can be cached with ETag .我希望文件可以用ETag缓存。 But it not works.但它不起作用。 I think that The If-None-Match not send to the server is the reason.我认为If-None-Match没有发送到服务器是原因。 So I want to get The 'ETag' from response headers.所以我想从响应头中获取“ETag”。 But the response header not has the item in Angular, But It's truly in the HTTP response in chrome network tool.但是响应头没有Angular中的项目,但它确实在chrome网络工具中的HTTP响应中。 All of showing in follow images.所有显示在以下图像中。

HttpClient 响应头

Http 响应头

How can I get the ETag from response Header如何从响应头中获取 ETag

I think it's similar to this : HttpClient dont return all headers .我认为它与此类似: HttpClient 不返回所有标头

You need to setup your backend to return Access-Control-Expose-Headers:ETag .您需要设置后端以返回Access-Control-Expose-Headers:ETag

As the MDN shows the cors hide lots of headers, So I can't get the ETag in angular.由于 MDN 显示cors隐藏了很多标题,所以我无法获得ETag的角度。

在此处输入图片说明

Add Access-Control-Expose-Headers:ETag to response header can solve this issue.Access-Control-Expose-Headers:ETag到响应头可以解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM