本文介绍了如果是HTTPS请求,如何找到node.js中的远程地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI。在node.js中,如果它是http请求,我可以在req.connection.remoteAddress获取remoteAddress,

HI. in node.js, if it is http request, I can get the remoteAddress at req.connection.remoteAddress,

那么,如果https请求如何获取它?我发现有req.socket.remoteAddress但我不确定。请指教。谢谢。

so, how to get it if https request? I find there is req.socket.remoteAddress but I'm not sure. Please advice. thanks.

推荐答案

看来确实有些奇怪/破碎。
从节点0.4.7开始,http似乎有remoteAddress可用:

It appears something is strange/broken indeed.As of node 0.4.7, it seems http has remoteAddress available on:


  • req.connection.remoteAddress
  • https上的
  • req.socket.remoteAddress

  • req.connection.remoteAddress
  • req.socket.remoteAddress

,这两个都是未定义的,但是

on https, both of these are undefined, but


  • req.connection.socket.remoteAddress

确实有效。
虽然这个不在http上,但是你需要仔细检查。
我无法想象这种行为是故意的。

does work.That one isn't available on http though, so you need to check carefully.I cannot imagine this behavior is intentional.

这篇关于如果是HTTPS请求,如何找到node.js中的远程地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 20:03