在今天学习nodejs基础知识过程中,创建服务器时
// 1.引入http模块
var http = require('http');
// 2.用http模块创建服务
http.createServer(function (req, res) { // req即request,表示获取URL信息; res即response,表示浏览器返回的相应信息。
// req和res可以随便写,一般写成req和res
// 3.1发送http状态头
// 200表示Ok
// 文件类型是html, 字符集是utf8
res.writeHead(202, {'Content-Type':'text/html;charset=UTF-8'});
// 3.2 发送响应
res.end('Phl你好!');
}).listen(8080);
// 4.打印日志信息
console.log('Server running at http://127.0.0.1:8080');
发现状态码不是202,而是404,502等状态码,也可以正常显示页面
具体原因不知为何。