express req object
来源:互联网 发布:阿里云 404 编辑:程序博客网 时间:2024/04/28 21:36
req.params
// get /user/kyfxbl/29app.get("/user/:id1/:id2", function (req, res) { console.log(req.params);// [ id1: 'kyfxbl', id2: '29' ] res.end("hello world");});
req.query
// get /user/kyfxbl/abc?age=29app.get("/user/:id1/:id2", function (req, res) { console.log(req.query);// { age: '29' } res.end("the id is: " + req.params.id1);});
req.body
这个是解析http请求体(post)的结果,需要use middleware(express.bodyParser)
req.param(name)
是一种简写,查找顺序依次是params, body, query
req.route
路由的信息:
app.get("/user/:id1/:id2", function (req, res) { console.log(req.route); res.end("the id is: " + req.params.id1);});
GET /user/kyfxbl/29,将会输出:
{ path: '/user/:id1/:id2', method: 'get', callbacks: [ [Function] ], keys: [ { name: 'id1', optional: false }, { name: 'id2', optional: false } ], regexp: /^\/user\/(?:([^\/]+?))\/(?:([^\/]+?))\/?$/i, params: [ id1: 'kyfxbl', id2: '29' ] }
req.cookies
cookie信息
req.get()
req.get('User-Agent');// 获取http request header中的信息
req.accepts()
Check if the given types
are acceptable, returning the best match when true, otherwise undefined
- in which case you should respond with 406 "Not Acceptable".
这个方法比较少用到
req.path
console.log(req.path);
GET /user/kyfxbl/29,返回/user/kyfxbl/29
还有一些特别一目了然的,一起贴了:
req.ip => client(browser) ip
req.host => localhost
req.protocol => http
另外还有一些都是跟http request header相关的查询方法,详见官方reference: express reference
- express req object
- node+express----请求对象req
- express req 获取入参方式
- express取参数req.query, req.params, req.body方法如何使用
- req
- nodejs express req.body 为undefined的一个bug
- Express框架req,res常用属性与方法
- nodejs -- express 之 req(响应)官方API 翻译
- express response object
- Express框架中的req.fresh属性何时返回true,何时返回false
- 启动COGNOS8服务的时候提示CM-REQ-4252 Unable to find the object "/directory"错误。
- Kotlin object express 匿名内部类
- #216. REQ
- node.js express传递object给ejs(二)
- 在eclipse使用到json时出现The type java.lang.Object cannot be resolved. It is indirectly referenced from req
- express
- express
- Express
- 错误:‘strcpy’在此作用域中尚未声明
- 读“一个 很高兴见到你“有感文章推荐
- NYOJ-509-因子和阶乘-2013年08月20日16:57:18
- 如何用Directshow进行视频或音频的裁剪
- acm-调用函数求a!+b!+c!的值
- express req object
- 在android布局中使用include和merge标签
- Floyd All Shortest Path 所有最短路径的查找 C++程序
- jetty的线程池实现QueuedThreadPool
- hdu 2680 Choose the best route
- NYOJ-67-三角形面积-2013年08月21日09:15:13
- hdu 4429 Split the Rectangle
- IOS 四种保存数据的方式
- 必须知道的HTML5十件事