使用nodejs的request包请求中文gb2312网页时会乱码,默认:
javascript
var request = require('request');
request(url, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
});
123456
需要进行转码:
javascript
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());
}
});
12345678910
评论 (0)