I am using node request module to do some get request.I am getting the response body like
{
body: '\u001f?\b\u0000\u0000\u0000\u0000\u0000...............'
}
i have the header parameters and request like this,
var params = {
url: options.url,
headers: {
'Accept-Encoding': "gzip, deflate",
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Charset' : 'utf-8',
'Content-Type' : 'application/json',
'User-Agent' : 'Mozilla/5.0'
}
};
request(params, function (error, response, body) {
//response.setEncoding('utf8');
//response.setEncoding('binary');
console.log(response);
})
I tried
//response.setEncoding('utf8');
//response.setEncoding('binary');
and new Buffer(response.body, 'ascii').toString('utf8')
to read the body content but its not working.
how to read the body content properly as JSON ?
This works using
zlib.createGunzip()