Express之get,pos请求参数的获取

2020-06-17 07:00:33易采站长站整理

localhost

ip

使用:req.ip


//http://localhost:3000/users/ip/get
router.get('/ip/get',function(req, res, next){
res.send(req.ip);
})

//结果:
::1

originalUrl

使用:req.originalUrl


//http://localhost:3000/users/originalUrl/get
router.get('/originalUrl/get',function(req, res, next){
res.send(req.originalUrl);
})

//结果:
/users/originalUrl/get

protocol

使用:req.protocol


//http://localhost:3000/users/protocol/get
router.get('/protocol/get',function(req, res, next){
res.send(req.protocol);
})

//结果:
http

secure

使用:req.secure

说明:用来判断协议是否安全,如果是https,返回的就是true


//http://localhost:3000/users/secure/get
router.get('/secure/get',function(req, res, next){
res.send(req.secure);
})

//结果:
false

xhr

使用:req.xhr

说明:判断是否是异步请求


//http://localhost:3000/users/xhr/get
router.get('/xhr/get',function(req, res, next){
res.send(req.xhr);
})

//结果:
false