1. Http请求
(1) 请求报文组成
- 请求行
- 请求头
- 请求体
(2) 请求方法
- GET:服务器获取数据
- POST:向服务器提交数据
- PUT:修改服务器内容
- DELETE:请求服务器删除指定的页面
(3) HTTP请求头
const http = require('http');
// 创建服务
const server = http.createServer(function (req,res) {
res.writeHeader(200,{
'Content-type':'text/html;charset=utf8'
});
for(let attr in req.headers){
res.write(`<p>`+attr+':'+req.headers[attr]+`</p>`);
}
res.write('<hr>');
res.write(`<p>`+'HTTP的版本号:'+req.httpVersion+`</p>`);
res.write(`<p>`+'请求方法:'+req.method+`</p>`);
res.write(`<p>`+'请求地址:'+req.url+`</p>`);
res.end();
});
server.listen(8086,function () {
console.log('http server is running on port 8086');
});