utf8 编码的内容utf8 编码的内容gbk// require
// 端口号
var http = require('http')
var server = http.createServer()
server.on('request', function (req, res) {
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
res.end('hello 世界')
server.listen(3000, function () {
console.log('Server is running...')
})

Content-Type 就是用来告知对方我给你发送的数据内容是什么类型 res.setHeader('Content-Type','text/plain; charset=utf-8')测试:
var http = require('http')
var server = http.createServer()
server.on('request',function(req,res){
res.setHeader('Content-Type','text/plain; charset=utf-8')
res.end('hello 世界!')
})
server.listen(3000,function(){
console.log('Server is running...');
})

text/plain就是普通文本html格式的字符串,则也要告诉浏览器我给你发送是text/html格式的内容var http = require('http')
var server = http.createServer()
server.on('request', function (req, res) {
var url = req.url
if (url === '/plain') {
// text/plain 就是普通文本
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
res.end('hello 世界')
} else if (url === '/html') {
// 如果你发送的是 html 格式的字符串,则也要告诉浏览器我给你发送是 text/html 格式的内容
res.setHeader('Content-Type', 'text/html; charset=utf-8')
res.end('<p>hello html <a href="">点我</a></p>')
}
})
server.listen(3000, function () {
console.log('Server is running...')
})localhost:3000/plain
localhost:3000/html
