Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 你能用Angular压缩get请求的内容吗?_Javascript_Angularjs_Gzip - Fatal编程技术网

Javascript 你能用Angular压缩get请求的内容吗?

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方法获取数据时,有没有办法将其压缩?假设源代码已经压缩,只需

我正在获取一些JSON,其中包含:

$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只有当客户端说“我可以接受压缩数据”时,服务器才应该压缩数据。现在大多数浏览器都禁止更改接受编码头。