简体   繁体   中英

NodeJS Encrypted HTTPS Response Body

I'm creating a small icloud client using node, so that I can pull down some of my data and analyze it. I'm currently scripting the login sequence. When I receive a response the headers are fine, and the session cookies i expect are there, but the response body which should be JSON looks encrypted, it's not even plain text. It's over SSL, but if the headers are readable, shouldn't the body be as well? Is there a setting I'm missing or a bug in node, i'm using the latest, 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���

According to the response header content-encoding: gzip , the response isn't encrypted, it's just compressed. You can use Node's zlib module to decompress it on the fly. Here's an example using my blog's homepage as the endpoint (since my server responds with gzipped data when asked):

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();

There are some more examples on the Node.js documentation for the zlib module .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM