node04_03解决中文乱码的问题
const http = require('http')
const server = http.createServer()
server.on('request',function(req,res){
const url = req.url
const method = req.method
const str = `请求的URL是${url},请求的method类型为${method}`
//调用res.setHerder()方法,设置Content-Type响应头,解决中文乱码问题
res.setHeader('Content-Type','text/html;charset=utf-8')
//res.end()将内容响应给客户端
res.end(str)
})
server.listen(80 ,()=>{
console.log('Server running at http://127.0.0.1')
})
//调用res.setHerder()方法,设置Content-Type响应头,解决中文乱码问题