demo39.js
const express = require('express'); const app = express(); const bodyParser = require('body-parser'); //拦截所有请求 //extends:true 方法内部使用第三方模块请求的参数 app.use(bodyParser.urlencoded({ extends: false })) app.post('/add', (req, res) => { res.send(req.body); }) app.listen(3000); console.log('服务器启动成功');
post.html
登录后复制 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <form action="http://localhost:3000/add" method="post"> <input type="text" name="username"> <input type="password" name="password"> <input type="submit" name=""> </form> </body> </html>