问题描述
- 两者之间有何不同
- 什么时候使用,什么情况下使用
假设客户端在请求中发送了一个说Android(密钥,值)对........要使用哪个对?
Suppose a client sends say Android (Key,value) pair in the request ........ which one to use ?
假设android发送POST请求->意图是向客户端发送(Key,Value),服务器应基于服务器中的值执行数据库查询并返回JSON响应
Suppose android sends a POST request -> Intention is to send (Key,Value) to client and the server should perform a database query based on the value in the server and return JSON response
查找::针对我引用的程序,出现以下问题::用于查询结果的Simple Express程序
推荐答案
req.query
将在解析查询字符串后返回JS对象.
req.query
will return a JS object after the query string is parsed.
/user?name = tom& age = 55 -req.query
将产生{name:"tom", age: "55"}
req.params
将在匹配的路由中返回参数.如果您的路线是/user/:id 并且您向/user/5 发出请求-req.params
将产生{id: "5"}
req.params
will return parameters in the matched route.If your route is /user/:id and you make a request to /user/5 - req.params
would yield {id: "5"}
req.param
是一个将参数从请求中剥离的功能.所有这些都可以在此处找到.
req.param
is a function that peels parameters out of the request. All of this can be found here.
更新
如果动词是POST
,并且您正在使用bodyParser
,那么您应该能够在使用req.body
的函数中获取表单主体.这将是POST
ed表单的已解析JS版本.
If the verb is a POST
and you are using bodyParser
, then you should be able to get the form body in you function with req.body
. That will be the parsed JS version of the POST
ed form.
这篇关于ExpressJS中的req.query和req.param的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!