温馨提示  2024年 6月我们已经停止开发者板块文章内容更新,谢谢来访。存档数据
知识 2023-08-25 46 次阅读

如何解决node res.write 乱码问题

   

node res.write乱码的解决方案 1. 设置头部信息为“content-type':'text/plain; charset=utf-8”; 2. 设置代码为“res.write(json.stringify({msg:data})”。

本文操作环境windows7系统,nodejs10.16.2版,dell g3电脑。

如何解决node res.write 乱码问题?

关于nodejs res.write返回中文乱码问题

需要添加头部信息:

'content-type': 'text/plain; charset=utf-8'

如下

res.writehead(200, {'content-type': 'text/plain; charset=utf-8'}); res.write(json.stringify({msg:data}),'utf8');

推荐学习《node.js视频教程》