使用网上查到的方法
req.host 、 require('url') 之类的解出来都是null...
例如:一个请求为
https://localhost:3000/test?a=1&b=2
Nodejs监听到请求并打印出这个请求
var router = require('express').Router();
router.all('/test',function(req, res){
// 打印出https://localhost:3000/test?a=1&b=2
});
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
req.orginalurl对象就是原始的url值,所以直接console.log就行了
你使用的是express,express已经进行了一次封装,就不用引入url模块,直接使用req.originalUrl,就可以获取url.
你把req打印出来就知道了。。。
express4中:
req.protocol+"://"+req.headers.host+req.originalUrl