我正在获取一些 Angular 为的JSON:

$http({
    url: 'https://www.somemachine.com/getdata',
    method: "GET",
    params: {}
}).success(function(data, status, headers, config) {
    console.log(data);
}

它接收的数据非常大,我很乐意gzip源代码,但是当我的$http方法获取它时,是否有一种方法可以将其压缩。

最佳答案

假设源已经压缩,只需确保在请求上将Accept-Encoding header 设置为gzip即可:

$http.get('https://www.somemachine.com/getdata', { headers: { 'Accept-Encoding': 'gzip' } }
).success(function(data, status, headers, config) {
    console.log(data);
});

当浏览器在响应中看到Content-Encoding = gzip header 时,它将自动将其解压缩。

关于javascript - 您可以在Angular中将获取请求的内容压缩到邮政编码吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18390343/

10-16 20:19