如何在节点中确定用户的IP地址如何从控制器内确定给定请求的IP地址?例如(以明示方式):app.post('/get/ip/address', function (req, res) {
// need access to IP address here})
3 回答
凤凰求蛊
TA贡献1825条经验 获得超4个赞
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || (req.connection.socket ? req.connection.socket.remoteAddress : null);
req.headers['x-forwarded-for']
x-forwarded-for
X-转发-用于: client, proxy1, proxy2, proxy3
proxy1
, proxy2
proxy3
. proxy3
x-forwarded-for
var ip = (req.headers['x-forwarded-for'] || '').split(',').pop() || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress
- 3 回答
- 0 关注
- 1209 浏览
添加回答
举报
0/150
提交
取消