P
P
Pavel Kilin2014-05-13 13:29:57
Node.js
Pavel Kilin, 2014-05-13 13:29:57

Why are there bugs in the node-request response?

Good afternoon. Interested in such a problem, why request in binary mode returns krakozyabry from utf-8 pages?
Example:

var request = require('request');

request({
    uri: 'http://www.cn.ru/',
    method: 'GET',
    encoding: 'binary' // режим получения кракозябр вместо ответа
}).on('response', function(res) {
    res.on('data', function(data) {
        // получаем кучу кракозябр
        console.log(data.toString());
    });
});

If we remove encoding: 'binary', then we get something more or less sane.
I use this mode so that non-utf-8 pages can be converted normally using node-iconv.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene Obrezkov, 2014-05-13
@ghaiklor

Because binary is still a binary data format. It will always return krakozyabry.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question