NodeJS加密的HTTPS响应正文

时间:2012-07-07 16:10:54

标签: node.js ssl https

我正在使用节点创建一个小型icloud客户端,这样我就可以下载一些数据并对其进行分析。我目前正在编写登录序列的脚本。当我收到回复时,标题很好,我期望的会话cookie就在那里,但应该是JSON的响应主体看起来是加密的,它甚至不是纯文本。这是通过SSL,但如果标题是可读的,身体不应该这样吗?是否有我缺少的设置或节点中的错误,我使用的是最新的0.8.1

{ date: 'Sat, 07 Jul 2012 14:51:56 GMT',
 'x-apple-request-uuid': '............',
 'x-responding-instance': '...........',
 'cache-control': 'no-cache, no-store, private',
 'access-control-allow-origin': 'https://www.icloud.com',
 'access-control-allow-credentials': 'true',
 'set-cookie': [........],
 'content-type': 'application/json; charset=UTF-8',
 'content-encoding': 'gzip',
 'content-length': '126' }
���������VJ-*�/R�R
K��LI,IUJ-,M-.Q��U��,.��KW��u�q�
wur
��
��v�SH����LU�Q��+.I�KN�bhldijiaaf/.MNN-.V�JK�)N��$���l���

1 个答案:

答案 0 :(得分:5)

根据响应标头content-encoding: gzip,响应未加密,只是压缩。您可以使用Node的zlib模块即时解压缩它。这是一个使用我的博客主页作为端点的示例(因为我的服务器在询问时使用gzip压缩数据进行响应):

http = require('http');
zlib = require('zlib');
url = require('url');

var uri = url.parse("http://brandontilley.com/");
uri.headers = {'accept-encoding': 'gzip'};

var request = http.get(uri, function(res) {
  var buffers = [];
  res.pipe(zlib.createGunzip()).on('data', function(chunk) {
    buffers.push(chunk);
  }).on('end', function() {
    console.log(Buffer.concat(buffers).toString());
  });
});
request.end();

Node.js documentation for the zlib module还有更多示例。

相关问题