-
-
Save dayitv89/7e013bdf56c8bd4e99e3d90240e0a3d6 to your computer and use it in GitHub Desktop.
Read http request's body which has a gzip content encoding (node.js);
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var https = require('https'); | |
var gunzip = require('zlib').createGunzip(); | |
var options = { | |
host: 'api.stackexchange.com', | |
path: '/2.1/info?site=stackoverflow' | |
}; | |
https.get(options, function(res) { | |
var body = ''; | |
res.pipe(gunzip); | |
gunzip.on('data', function (data) { | |
body += data; | |
}); | |
gunzip.on('end', function() { | |
console.log(JSON.parse(body)); | |
}); | |
gunzip.on('error', function(error) { | |
console.log(error); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment