nodejs中的HTTP请求
来源:互联网 发布:adobe cc mac 注册机 编辑:程序博客网 时间:2024/04/30 19:03
get 和 post 的第一个参数都为请求的路径,第二个参数为处理请求的回调函数,回调函数有两个参数分别是 req 和 res,代表请求信息和响应信息 。路径请求及对应的获取路径有以下几种形式:
req.query
- // 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"
- req.query.shoe.type
- // => "converse"
- // POST user[name]=tobi&user[email]=tobi@learnboost.com
- req.body.user.name
- // => "tobi"
- req.body.user.email
- // => "tobi@learnboost.com"
- // POST { "name": "tobi" }
- req.body.name
- // => "tobi"
req.params
- // GET /user/tj
- req.params.name
- // => "tj"
- // GET /file/javascripts/jquery.js
- req.params[0]
- // => "javascripts/jquery.js"
- **req.param(name)**
- // ?name=tobi
- req.param('name')
- // => "tobi"
- // POST name=tobi
- req.param('name')
- // => "tobi"
- // /user/tobi for /user/:name
- req.param('name')
- // => "tobi"
req.query:处理get请求
req.body:: 处理 post 请求
req.params: 处理 /:xxx 形式的 get 请求
req.param(): 可以处理 get 和 post 请求,但查找优先级由高到低为req.params→req.body→req.query
0 0
- nodejs中的HTTP请求
- nodejs http 发送请求
- nodejs http 发送请求
- nodejs http post 请求
- nodejs中的http简介
- Nodejs 发送HTTP POST请求实例
- nodejs入门之基础HTTP请求
- nodejs入门之基础HTTP请求
- nodejs http.request 发送请求demo
- Nodejs 发送HTTP POST请求实例
- nodejs使用request发送http请求
- nodejs获取http请求的传入数据
- nodejs中http协议的客户端请求
- nodejs 发起http get post 请求
- HTTP请求中的请求字段
- python中的http请求
- Swift中的HTTP请求
- http请求中的referer
- onenote备份
- mina作为客户端断线重连
- mybatis使用汇总
- Redis学习手册(Set数据类型)
- 使用struts、hibernate、spring进行框架整合流程详细说明(完整版)
- nodejs中的HTTP请求
- NSNotificationCenter消息机智kvo
- 阻止enter键提交表单(监听了onkeydown事件)js代码
- app 上传审核详解
- linux的简要设置及操作入门
- Oracle将查询结果存入临时表的写法
- 常见Java面试题 – 第二部分:equals与==
- CCCallFunc
- ubuntu12.04通过Ganglia利用NVML模块进行GPU监控