我需要往一个网站 post一组数据 ,目标网站只接收gb2312编码的。其它接到是乱码。
nodejs如何把utf-8的字符转化为gb2312?
var iconv = require('iconv-lite');
var str = '你好';
str = iconv.encode(str,'utf8');
str = iconv.decode(str,'GB2312');
str = str.toString();
console.log(str);
这样是不行的。求指导
大家讲道理2017-04-17 14:38:13
I have encountered this before, you can take a look at this http://web-engineer.cn/article/29
天蓬老师2017-04-17 14:38:13
The first floor is great, superAgent-charset realizes the function! ! !
It’s a pity that my reputation cannot reach 15
I made a corresponding summary, you can see: Link description
Using NodeJs to implement news Rss crawler
伊谢尔伦2017-04-17 14:38:13
iconv.encode(testString, 'utf8').toString('gb2312')
https://github.com/ashtuchkin...
ringa_lee2017-04-17 14:38:13
var iconv = require('iconv-lite');
....
body = iconv.decode(body, 'gbk');