spring boot 获取ip
2021-03-06 02:27
标签:获取ip ring real head ase servlet cas ignore object 按照我这个代码,如果有代理过的,基本也能获取到IP地址。 spring boot 获取ip 标签:获取ip ring real head ase servlet cas ignore object 原文地址:https://www.cnblogs.com/ilii/p/14311511.htmlspring boot 获取ip 地址
public String getRemoteHost(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (ObjectUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("x-real-ip");
}
if (ObjectUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
上一篇:数组形式的整数加法