服务器处理请求之POST
1.创建index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method="get" action="http://localhost:8080/login" name="form1">
用户名:<input type="text" id="user" name="user"><br/>
密码:<input type="password" id="pswd" name="pswd"><br/>
<input type="submit" value="登录">
</form>
</body>
</html>
2.创建server.js
const http=require('http');
http.createServer(function (req, res){
var str=''; //声明一个空的字符串,用户接收前端发过来的数据
var i=1;
req.on('data', function (data){
str+=data;
console.log(`第${i++}次收到数据`);
});
req.on('end', function (){
res.end('str:'+str);
});
}).listen(8080,function(){
console.log("The server is running!")
});
3.启动node服务
node server.js
4.访问服务器端口
http://localhost:8080/login