我需要往一个网站 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);
这样是不行的。求指导
欢迎选择我的课程,让我们一起见证您的进步~~
I have encountered this before, you can take a look at this http://web-engineer.cn/article/29
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
iconv.encode(testString, 'utf8').toString('gb2312')
https://github.com/ashtuchkin...
var iconv = require('iconv-lite');
....
body = iconv.decode(body, 'gbk');
I have encountered this before, you can take a look at this http://web-engineer.cn/article/29
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
https://github.com/ashtuchkin...
var iconv = require('iconv-lite');
....
body = iconv.decode(body, 'gbk');