编程语言
首页 > 编程语言> > node中res.write内容出现中文乱码

node中res.write内容出现中文乱码

作者:互联网

解决:添加编码方式utf-8

const http = require('http')
http.createServer(function(req, res){
    console.log(req.url)
    res.writeHead(200,{ "Content-Type": "text/plain;charset=utf-8" })
    res.write("hello word你好!")
    res.end()
}).listen(8080)

如果添加之后还是乱码,注意找不同,我之前就是把text/plain写成text-plain了,emmmm。

标签:node,http,plain,req,res,乱码,text
来源: https://blog.csdn.net/apple_2021/article/details/121952471