您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

浅谈node中文乱码的解决方法

2025/10/23 13:22:33发布26次查看
相关推荐:《nodejs 教程》
今天咋学习node的时候,跟着视频里在撸代码,但是却出现了中文乱码的情况,视频中的谷歌浏览器可能和我的版本不一致,先看代码吧:
'use strict';const http = require("http");let count = 0;const server = http.createserver((req, res) => { res.write(`这是第${count++}个访问的`); res.end();});server.listen(2080, error => { if (error) throw error; console.log("启动成功")});
我是想用node建一个本地的服务器,然后统计访问的个数,但是却出现了中文乱码:
杩欐槸绗�0涓闂殑后来查询资料,原来加一个头部代码就行:设置 res.writehead(200, {'content-type': 'text/html; charset=utf-8'});
'use strict';const http = require("http");let count = 0;const server = http.createserver((req, res) => { res.writehead(200, {'content-type': 'text/html; charset=utf-8'}); res.write(`这是第${count++}个访问的`); res.end();});server.listen(2080, error => { if (error) throw error; console.log("启动成功")});
更多编程相关知识,请访问:编程学习网站!!
以上就是浅谈node中文乱码的解决方法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product