node.js - nodejs request iconv-lite decode的时候报buffer错误
PHP中文网
PHP中文网 2017-04-17 13:36:51
0
1
731

nodejs中,用request获取代码,iconv解析gbk编码的时候,总是报错
....\node_modules\iconv-lite\encodings\dbcs-codec.js:452

var newBuf = new Buffer(buf.length*2),
                           ^

TypeError: Cannot read property 'length' of undefined

源代码:

var request = require('request');
var iconv = require('iconv-lite');

var options = {
    url : url,
    encoding: null
};
request(options, function(error,response,body) {

    var buf = iconv.decode(body, 'gb2312');
    console.log(buf);

});

求大神了~~

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
左手右手慢动作

Check whether the body information has data. I also encountered it. The passed parameter was undefined, so this error was reported

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template