问题原因:乱码,中文编码问题
原代码:
const http = require('http');
//
const app = http.createServer();
app.on('request', (req, res) => {
res.writeHead(200, {
'content-type': 'text/html'
});
if (req.url == '/' || req.url == '/index') {
res.end("<h1> hello h1 你好</h1>");
}
console.log(req.headers);
console.log(req.url);
// res.end('<h1>hellofag word</h1>');
});
app.listen(3000);
console.log("active web ");
解决:添加编码方式utf8
const http = require('http');
//
const app = http.createServer();
app.on('request', (req, res) => {
res.writeHead(200, {
'content-type': 'text/html;charset=utf8'
});
if (req.url == '/' || req.url == '/index') {
res.end("<h1> hello h1 你好</h1>");
}
console.log(req.headers);
console.log(req.url);
// res.end('<h1>hellofag word</h1>');
});
app.listen(3000);
console.log("active web ");