Express的版本4.X
Get
query参数的获取
url假设: 1.获取"htmlcode">
结果: Post post的数据获取 1.获取需要的query参数 具体代码: 结果: 其他信息 获取请求的头信息 使用:req.header(field) route 使用:req.route cookies 使用:req.cookies hostname 使用:req.hostname ip 使用:req.ip originalUrl 使用:req.originalUrl protocol 使用:req.protocol secure 使用:req.secure 说明:用来判断协议是否安全,如果是https,返回的就是true xhr 使用:req.xhr 说明:判断是否是异步请求 以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!http://localhost:3000/users/zqzjs"htmlcode">
router.get('/:name', function(req, res, next) {
})
//http://localhost:3000/users/zqzjs"Params"+
"<p><strong>req.params:</strong>"+(JSON.stringify(req.params) || '')+"</p>" +
"<p><strong>req.params.name:</strong>"+(req.params.name || '')+"</p>" +
"Query:" +
"<p><strong>req.query:</strong>"+(JSON.stringify(req.query) || '')+"</p>" +
"<p><strong>req.query.name:</strong>"+(req.query.name || '')+"</p>" +
"<p><strong>req.query.word:</strong>"+(req.query.word || '')+"</p>"+
"<p><strong>req.query.job.st:</strong>"+(req.query.job.st || '')+"</p>" +
"<p><strong>req.param('name'):</strong>"+(req.param('name') || '')+"</p>" ;
res.send(_html);
});
[Get]
Params
req.params:{"name":"zqzjs"}
req.params.name:zqzjs
Query:
req.query:{"name":"zhaoqize","word":"cool","job":{"st":"web"}}
req.query.name:zhaoqize
req.query.word:cool
req.query.job.st:web
req.param('name'):zqzjs
Form Data
pName:zqz
pWord:job
req.body.pName
router.post('/postTest',function(req, res, next){
var _html = "[Post]" +
"<p><strong>req.body:</strong>"+(JSON.stringify(req.body) || '')+"</p>" +
"<p><strong>req.body.name:</strong>"+(req.body.pName || '')+"</p>" +
"<p><strong>req.body.name:</strong>"+(req.body.pWord || '')+"</p>";
res.send(_html);
})
[Post]
req.body:{"pName":"zqz","pWord":"job"}
req.body.name:zqz
req.body.name:job
//http://localhost:3000/users/requestInfo/get
router.get('/requestInfo/get',function(req, res, next){
var _html = "";
_html += "[Accept] "+req.header('Accept')+"<br/>"
_html += "[Accept-Encoding] "+req.header('Accept-Encoding')+"<br/>"
_html += "[Accept-Language] "+req.header('Accept-Language')+"<br/>"
_html += "[Cache-Control] "+req.header('Cache-Control')+"<br/>"
_html += "[Connection] "+req.header('Connection')+"<br/>"
_html += "[Cookie] "+req.header('Cookie')+"<br/>"
_html += "[Host] "+req.header('Host')+"<br/>"
_html += "[If-None-Match] "+req.header('If-None-Match')+"<br/>"
_html += "[Upgrade-Insecure-Requests] "+req.header('Upgrade-Insecure-Requests')+"<br/>"
_html += "[User-Agent] "+req.header('User-Agent')+"<br/>"
res.send(_html);
})
//结果:
[Accept] text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
[Accept-Encoding] gzip, deflate, sdch, br
[Accept-Language] zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4,ja;q=0.2
[Cache-Control] max-age=0
[Connection] keep-alive
[Cookie] Hm_lvt_4f16d955a2236fc6ca7287644ecc9d79=1480576847,1481166685
[Host] localhost:3000
[If-None-Match] W/"23b-OjTNcZfCLTvw659CYGlLrA"
[Upgrade-Insecure-Requests] 1
[User-Agent] Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36
//http://localhost:3000/users/router/get
router.get('/router/get',function(req, res, next){
res.send(req.route);
})
//结果:
{
path: "/router/get",
stack: [
{
name: "<anonymous>",
keys: [ ],
regexp: { },
method: "get"
}
],
methods: {
get: true
}
}
//http://localhost:3000/users/cookies/get
router.get('/cookies/get',function(req, res, next){
res.send(req.cookies);
})
//结果:
{
Hm_lvt_4f16d955a2236fc6ca7287644ecc9d79: "1480576847,1481166685"
}
//http://localhost:3000/users/hostname/get
router.get('/hostname/get',function(req, res, next){
res.send(req.hostname);
})
//结果:
localhost
//http://localhost:3000/users/ip/get
router.get('/ip/get',function(req, res, next){
res.send(req.ip);
})
//结果:
::1
//http://localhost:3000/users/originalUrl/get
router.get('/originalUrl/get',function(req, res, next){
res.send(req.originalUrl);
})
//结果:
/users/originalUrl/get
//http://localhost:3000/users/protocol/get
router.get('/protocol/get',function(req, res, next){
res.send(req.protocol);
})
//结果:
http
//http://localhost:3000/users/secure/get
router.get('/secure/get',function(req, res, next){
res.send(req.secure);
})
//结果:
false
//http://localhost:3000/users/xhr/get
router.get('/xhr/get',function(req, res, next){
res.send(req.xhr);
})
//结果:
false
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 第五街的士高《印度激情版》3CD [WAV+CUE][2.4G]
- 三国志8重制版哪个武将智力高 三国志8重制版智力武将排行一览
- 三国志8重制版哪个武将好 三国志8重制版武将排行一览
- 三国志8重制版武将图像怎么保存 三国志8重制版武将图像设置方法
- 何方.1990-我不是那种人【林杰唱片】【WAV+CUE】
- 张惠妹.1999-妹力新世纪2CD【丰华】【WAV+CUE】
- 邓丽欣.2006-FANTASY【金牌大风】【WAV+CUE】
- 饭制《黑神话》蜘蛛四妹手办
- 《燕云十六声》回应跑路:年内公测版本完成95%
- 网友发现国内版《双城之战》第二季有删减:亲亲环节没了!
- 邓丽君2024-《漫步人生路》头版限量编号MQA-UHQCD[WAV+CUE]
- SergeProkofievplaysProkofiev[Dutton][FLAC+CUE]
- 永恒英文金曲精选4《TheBestOfEverlastingFavouritesVol.4》[WAV+CUE]
- 群星《国风超有戏 第9期》[320K/MP3][13.63MB]
- 群星《国风超有戏 第9期》[FLAC/分轨][72.56MB]