Javascript 你能用Angular压缩get请求的内容吗?
我正在获取一些JSON,其中包含:Javascript 你能用Angular压缩get请求的内容吗?,javascript,angularjs,gzip,Javascript,Angularjs,Gzip,我正在获取一些JSON,其中包含: $http({ url: 'https://www.somemachine.com/getdata', method: "GET", params: {} }).success(function(data, status, headers, config) { console.log(data); } 它接收的数据非常大,我很乐意gzip源代码,但是当我的$http方法获取数据时,有没有办法将其压缩?假设源代码已经压缩,只需
$http({
url: 'https://www.somemachine.com/getdata',
method: "GET",
params: {}
}).success(function(data, status, headers, config) {
console.log(data);
}
它接收的数据非常大,我很乐意gzip源代码,但是当我的
$http
方法获取数据时,有没有办法将其压缩?假设源代码已经压缩,只需确保在请求时将Accept Encoding标头设置为gzip:
$http.get('https://www.somemachine.com/getdata', { headers: { 'Accept-Encoding': 'gzip' } }
).success(function(data, status, headers, config) {
console.log(data);
});
当浏览器在响应上看到Content Encoding=gzip标题时,它会自动解压缩。您的第一句话没有意义。当服务器压缩数据时,为什么客户端会说“我希望压缩”?@zeroflagL只有当客户端说“我可以接受压缩数据”时,服务器才应该压缩数据。现在大多数浏览器都禁止更改接受编码头。