[英]Is it possible to get the domain or ip address if the request came from?
I am trying to put security in the controller , by checking the domain or ip address from the request and compare it to the domain that is save in the database.我试图通过检查请求中的域或 IP 地址并将其与保存在数据库中的域进行比较来将安全性置于控制器中。 But I'm having a problem on how to get the client ip address.
但是我在如何获取客户端 IP 地址方面遇到了问题。 I'm using spring-boot java .
我正在使用 spring-boot java 。 Is there anyone know how to do it ?
有没有人知道怎么做?
This could help这可以帮助
public static String getRequester(HttpServletRequest request) {
String forwardHeader= request.getHeader("X-Forwarded-For");
if (forwardHeader == null) {
return request.getRemoteAddr();
} else {
return new StringTokenizer(forwardHeader, ",").nextToken().trim();
}
}
Reference 2 - https://www.mkyong.com/java/how-to-get-client-ip-address-in-java/参考 2 - https://www.mkyong.com/java/how-to-get-client-ip-address-in-java/
Reference 1 - https://en.wikipedia.org/wiki/X-Forwarded-For参考 1 - https://en.wikipedia.org/wiki/X-Forwarded-For
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.