//引入http模块
const http = require('http');
//获取url地址中的参数
const url = require('url');
//把query字符串转换为对象
const querystring = require('querystring');
//创建web实例
http.createServer((req,res) => {
// 接受post数据
if(req.mothod === 'POST'){
//数据容器
let postDate = '';
//数据开始发送接收
req.on('data',buffer => postDate += bufffer)
// 数据接收完毕
req.on('end',() => {
//接受完毕后,响应
let json = JSON.stringify(querystring.parse(postDate));
res.end(json);
})
}else{
res.end('ok')
}
}).listen(7878,'0.0.0.0',() => console.log('server start ...'))
Node Js中post数据获取
最新推荐文章于 2023-10-22 13:48:48 发布