I use a gzip json static file on my server (actually, it's my test server) and the data i receive is always compressed.
Here is my code :
$http({
url :'app/assets/json/makes2v.json.gz',
method: "GET",
headers: { 'Accept-Encoding': 'gzip' }})
.success(function(data, status, headers, config) {
console.log(data);
});
I use angular 1.3.15 and Chrome.
In the console I have this error:
Refused to set unsafe header "Accept-Encoding"
Any help will be appreciated.
Thanks,
The solution would be to deactivate gzip encoding in the portal and perform any necessary gzip encoding through the HTTP server. However, the gzip encoding cannot be deactivated through a central portal property.
To check this Accept-Encoding in action go to Inspect Element -> Network check the request header for Accept-Encoding like below, Accept-Encoding is highlighted you can see.
The Accept-Encoding header is used for negotiating content encoding. Accept-Encoding: gzip, deflate. The server responds with the scheme used, indicated by the Content-Encoding response header. Content-Encoding: gzip. Note that the server is not obligated to use any compression method.
The Accept-Encoding request HTTP header indicates the content encoding (usually a compression algorithm) that the client can understand. The server uses content negotiation to select one of the proposals and informs the client of that choice with the Content-Encoding response header.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With