const http=require('http');
const fs=require('fs');
const querystring=require('querystring');
const urlLib=require('url');
var server=http.createServer(function(req,res){
//GET
var obj=urlLib.parse(req.url,true);
console.log(obj.query);
console.log(obj.pathname);
//post
var str='';
req.on('data',function(data){
str+=data;
});
req.on('end',function(){
// console.log(str); uname=jack&upd=123
var result=querystring.parse(str);
console.log(result);
})
//fs 文件
var file_name='./www'+req.url;
fs.readFile(file_name,function(err,data){
if(err){
res.write('404');
}else{
res.write(data)
}
res.end();
})
});
server.listen(8080);
//querysyring url
//get post
const http=require('http');
const querystring=require('querystring');
var server=http.createServer(function(req,res){
var str='';
req.on('data',function(data){//每次传输的数据
str+=data;
})
req.on('end',function(){//数据传输完成
var post=querystring.parse(str);
console.log(post);//uname=jack&upwd=123
})
});
server.listen(8080);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form action="http://localhost:8080" method="post">
登录:<input type="" value="" name="558" />
密码:<input type="" value="" name="123" />
<input type="submit" value="提交" />
</form>
</body>
</html>