get 见093url系统模块处理请求地址GET
https://blog.csdn.net/Gy_9543/article/details/107623078
POST
post的数据在请求报文中
post参数是通过事件的方式接受的
// 创建web服务器
// 引用系统模块
const http = require('http');
// 创建web服务器
const app = http.createServer();
const querystring=require('querystring');
// 处理请求参数模块类似get的url
// 当客户端发送请求的时候
app.on('request', (req, res) => {
// 接收post参数
// post参数是通过事件的方式接受的
// data事件 当请求参数传递的时候触发data事件
// end事件 当参数传递完成的时候触发end事件
let postParams='';
req.on('data',(params)=>{
postParams+=params;
})
req.on('end',()=>{
console.log(querystring.parse(postParams).password);
console.log(postParams);
})
res.end('ok');
});
// 监听3000端口
app.listen(3000);
console.log('服务器已启动,监听3000端口,请访问localhost:3000')
字符串格式不容易获取参数
querystring模块
querystring.parse()可以将字符串转换为对象