var request = require('request');
request(url, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);//请求到数据会乱码
}
});
解决方案
- 设置encoding
- 使用Iconv 解密
var request = require('request');
var Iconv = require('iconv-lite');
request({encoding: null, url: url}, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(Iconv.decode(body, 'gb2312').toString());
}
});
网友评论