Angular gzip json文件自动:拒绝设置不安全的标头"Accept-Encoding" [英] Angular gzip json file automatically : Refused to set unsafe header "Accept-Encoding"

查看:968
本文介绍了Angular gzip json文件自动:拒绝设置不安全的标头"Accept-Encoding"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器(实际上是我的测试服务器)上使用了一个gzip json静态文件,并且接收到的数据总是被压缩.

I use a gzip json static file on my server (actually, it's my test server) and the data i receive is always compressed.

这是我的代码:

    $http({ 
      url :'app/assets/json/makes2v.json.gz',
      method: "GET",
      headers: { 'Accept-Encoding': 'gzip' }})
    .success(function(data, status, headers, config) {
      console.log(data);
  });

我使用的是Angle 1.3.15和Chrome.

I use angular 1.3.15 and Chrome.

在控制台中,我出现此错误:

In the console I have this error:

Refused to set unsafe header "Accept-Encoding"

任何帮助将不胜感激.

谢谢

推荐答案

您不应将请求标头设置为"Accept-Encoding".这是由浏览器自动设置的.请参阅此 Q& A 列出接受gzip的浏览器.

You shouldn't set the request header "Accept-Encoding". This is set automatically by the browser. See this Q&A for a list a browsers that accept gzip.

在服务器端,您需要将Content-Encoding设置为:

On the server side, you will need to set the Content-Encoding to:

Content-Encoding: gzip

然后,响应应由浏览器自动解压缩.

Then the response should be automatically decompressed by the browser.

这篇关于Angular gzip json文件自动:拒绝设置不安全的标头"Accept-Encoding"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆