【发布时间】:2018-12-10 23:07:48
【问题描述】:
这应该是一个简单的问题,但为了我的生活,我无法让它工作,我正在使用这样的网络服务:
var XMLHttpRequest = require('XMLHttpRequest').XMLHttpRequest;
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://rest.gestionix.com/api/v2/products?
branch_id=7471&filter=0119080PMDSV&results_per_page=5&page=1&fields=id');
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
xhr.onreadystatechange = function(event) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.responseText);
}
}
console.log(xhr.getAllResponseHeaders());
};
xhr.setRequestHeader('Accept','application/json');
xhr.setRequestHeader('Accept-Encoding','decode');
xhr.setRequestHeader('Content-Encoding','decode');
xhr.setRequestHeader('Encoding','decode');
xhr.setRequestHeader('apikey', '---'); <<< of course I'm using an apikey
xhr.send();
api 返回这个头文件:
cache-control: max-age=60
content-length: 22766
content-type: application/json
content-encoding: deflate
server: Microsoft-IIS/10.0
x-aspnet-version: 4.0.30319
x-powered-by: ASP.NET
date: Mon, 02 Jul 2018 16:31:32 GMT
connection: close
然而,内容只是一堆奇怪的字符:
��a�^G4Wk�wC�����p�Ȳ�G�?FZ}�Ϧ��Bo�W��i�gu��$H�^; ,Wf�촞�}�: �����P������e��yE�%6٬e1D�ml�7UO�DzK����m��}t�"���u ��dS7�Q��>5�y� I�;E�PH�}��/��X���&���W{�)X�SP��v�[�����k�W����P{�W �>Z����י�R��4T�]X�m����������������������������������������������������q .t� ��������&�Ǧ��oP���- ��;( ��4����o6��
我尝试过使用不同的编码,但结果始终相同,我已经寻找有关如何解压缩的文档,但我没有找到任何有效的方法,如果有人有可以指向正确方向的链接我会很感激的。
【问题讨论】:
标签: node.js api xmlhttprequest deflate