cari

Rumah  >  Soal Jawab  >  teks badan

node.js - nodejs request iconv-lite decode的时候报buffer错误

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中文网2779 hari yang lalu730

membalas semua(1)saya akan balas

  • ringa_lee

    ringa_lee2017-04-17 13:38:51

    你看一下body的信息是否有数据,我也遇到了,传的参数undefined,所以报的这个错

    balas
    0
  • Batalbalas