Nodejs request 数据乱码问题

安装

npm install iconv-lite

使用


var iconv = require('iconv-lite'); //引入模块

request({
     url: 'http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=18888888888',
     encoding: null //设置encoding
 }, function(error, response, body) {
     if (!error && response.statusCode == 200) {
         var buf = iconv.decode(body, 'gb2312').toString(); //解码gb2312
         console.log(buf);
     }
 });

你可能感兴趣的:(nodejs)