在node开发中,服务器启动后,在浏览器访问时,中文会出现乱码的解决方法
const http=require("http");
const server=http.createServer((req,res)=>{
res.setHeader('Content-Type', 'text/html;charset=UTF-8')//解决乱码
res.end('<h1>我的网站</h1><p>此网站基于node开发</p>');
});
server.listen(3000,()=>{
console.log("server is runing");
});
只要把字符集编码的方式设置为 UTF-8就好了