简体   繁体   English

总是从Servlet获取:: 1作为客户端IP地址

[英]Always Getting ::1 for Client IP Address from Servlet

I'm not sure why I'm always getting ::1 for IP Address from the header. 我不确定为什么总是从标题中获取IP地址的:: 1。

System.out.println("IP Address: " + request.getHeader("X-FORWARDED-FOR"));

IP Address: ::1

The proxy we use is Apache2 Reverse Proxy. 我们使用的代理是Apache2反向代理。 Any idea? 任何想法?

First be sure that this header is actually coming in the http packet using a network analayzer such as Wireshark. 首先,请确保使用网络分析器(例如Wireshark)将此标头实际上输入到http数据包中。 Once you are sure about it, then try to print all the headers to be sure that header is set in the ServletHttpRequest object. 确定后,请尝试打印所有标头,以确保在ServletHttpRequest对象中设置了标头。 If you get through all this, you can be sure where the problem is. 如果您解决了所有这些问题,则可以确定问题出在哪里。

Hope it helps! 希望能帮助到你!

请用

request.getHeader("REMOTE_ADDR")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM