最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can you gunzip the contents of a get request in Angular? - Stack Overflow

programmeradmin4浏览0评论

I'm fetching some JSON with angular as:

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

The data it's receiving is quite large, and I'm happy to gzip the source but is there a way to gunzip it when my $http method fetches it?

I'm fetching some JSON with angular as:

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

The data it's receiving is quite large, and I'm happy to gzip the source but is there a way to gunzip it when my $http method fetches it?

Share Improve this question asked Aug 22, 2013 at 20:35 nickponlinenickponline 25.9k34 gold badges106 silver badges179 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Assuming the source is already zipped, just ensure the Accept-Encoding header is set to gzip on the request:

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

The browser will automatically unzip it when it sees the Content-Encoding=gzip header on the response.

发布评论

评论列表(0)

  1. 暂无评论