1、req.query 处理GET请求 ,获取GET参数
//GET /search?q=tobi+ferret
req.query.q
//=>"tobi ferret"
//GET /shoes?order=desc&shoe[color]=blue&shoe[type]=converse
req.query.order
//=>"desc"
req.query.shoe.color
//=>"blue"
2、req.body 处理POST请求,获取POST参数
//POST user[name]=tobi&user[email][email protected]
req.body.user.name
//=>"tobi"
//POST {"name": "tobi"}
req.body.name
//=>"tobi"
3、req.params 处理/xxx形式的GET/POST请求
//GET /user/tj
req.params.user
//=>"tj"
//GET /js/javascript/jquery.js
req.params[0]
//=>"javascript/jquery.js"
4、req.param() 处理GET/POST请求,但查找优先级由高到低为 req.params-->req.body-->req.query
//?name=tobi
req.param(‘name‘)
//=>"tobi"
//POST name=tobi
req.param(‘name‘)
//=>"tobi"
时间: 2024-10-23 19:31:26