res.params
用于get请求
url路径为:http://localhost:3000/list/001/21
路由代码:
app.get('/list/:id/:age',(req,res)=>{
res.send(req.params)
//浏览器页面结果: {"id":"001","age":"21"}
})
res.query
用于get请求
url路径为:http://localhost:3000/form?username=1&pwd=1
路由代码:
app.get('/form',(req,res)=>{
console.log(req.query)
res.send(req.query)
// {"username":"1","pwd":"1"}
})
form表单:
<form action="http://localhost:3000/form" method="get">
用户名:<input type="text" name="username">
密码:<input type="text" name="pwd" id="">
<input type="submit">
</form>
res.body
用于post请求
url路径为:http://localhost:3000/form
路由代码:
app.post('/form',(req,res)=>{
console.log(req.body)
res.send(req.body)
// {"username":"1","pwd":"1"}
})
form表单:
<form action="http://localhost:3000/form" method="post">
用户名:<input type="text" name="username">
密码:<input type="text" name="pwd" id="">
<input type="submit">
</form>