SamDecrock / node-http-ntlm

Node.js module to authenticate using HTTP NTLM
MIT License
192 stars 89 forks source link

res.on('data')? #79

Closed Dror-Bar closed 6 years ago

Dror-Bar commented 6 years ago

Hi, I'm trying to get a response from a server with incorrect encoding. For that I need to decode a buffer of the response before it becomes an (incorrectly) utf8 encoded string. is it possible to use res.on() with this with this library? for example:

http.get("http://website.com/", function(res) {
  var chunks = [];
  res.on('data', function(chunk) {
    chunks.push(chunk);
  });
  res.on('end', function() {
    var decodedBody = iconv.decode(Buffer.concat(chunks), 'win1252');
    console.log(decodedBody);
  });
});

If I try this:

httpntlm.get({
                url: url,
                username: username,
                password: password,
                domain: domain,
            },
                function (err, res) {
                    if (err) { console.log(err); return; }
                    var chunks = [];
                    res.on('data', function (chunk) {
                        chunks.push(chunk);
                    });
                    res.on('end', function () {
                    console.log(chunks)
            });

I get an error 'res.on() is not a function'. Is there any solution? or any other way to get the response as a buffer?

Dror-Bar commented 6 years ago

I have managed to get what I need using binary: true and encoding library:

httpntlm.get({
                url: url,
                username: username,
                password: password,
                domain: domain,
                binary: true
            },
                function (err, res) {
                    if (err) { console.log(err); return; }
                   const decodedBody = encoding.convert(res.body, 'UTF-8', 'CP1255');
                   console.log(decodedBody);
            });