node.js - nodejs如何把utf-8的字符转化为gb2312
天蓬老师
天蓬老师 2017-04-17 14:36:13
0
4
656

我需要往一个网站 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); 

这样是不行的。求指导

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(4)
大家讲道理

I have encountered this before, you can take a look at this http://web-engineer.cn/article/29

Peter_Zhu

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');

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template