Kinaan Khan Sherwani Kinaan Khan Sherwani - 1 year ago 87
HTML Question

nodejs - request.get(url) returning binary data in case of

I am trying to run the following javascript code.

request = require('request')
request.get('',function(err,res,body){ console.log(err ? err.message : body) })

But it is logging binary data whereas
string is expected.

The same code returns
response if I replace the first argument with a different url say

I have tried the same in ruby with following code

puts open('').read

It returns correct html response in both cases.

I think I am missing something while using
package of nodejs.

Answer Source

You just see gzip-encoded html string. Use gzip option (docs) to get decompressed body.

request.get({url: '', gzip: true}, function(err,res,body){ console.log(err ? err.message : body) })
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download