我在我的服务器上使用 gzip json 静态文件(实际上,这是我的测试服务器),并且我收到的数据始终是压缩的。
这是我的代码:
$http({
url :'app/assets/json/makes2v.json.gz',
method: "GET",
headers: { 'Accept-Encoding': 'gzip' }})
.success(function(data, status, headers, config) {
console.log(data);
});
我使用 Angular 1.3.15 和 Chrome。
在控制台中我遇到此错误:
Refused to set unsafe header "Accept-Encoding"
任何帮助将不胜感激。
谢谢
最佳答案
您不应设置请求 header “Accept-Encoding”。这是由浏览器自动设置的。看这个Q&A获取接受 gzip 的浏览器列表。
在服务器端,您需要将内容编码设置为:
Content-Encoding: gzip
然后浏览器应该自动解压缩响应。
关于json - Angular gzip json 文件自动 : Refused to set unsafe header "Accept-Encoding",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32463340/