java获取用户请求的ip

xiaoxiao2021-02-28  28

/** * 获取用户ip * @param request * @return */ public static String getClientIP(HttpServletRequest request) { String remoteAddrHaProxy = (String) request .getHeader("x-forwarded-for"); String remoteAddr = null; if (StringUtils.isNotBlank(remoteAddrHaProxy)) { remoteAddr = remoteAddrHaProxy; } else { remoteAddr = request.getRemoteAddr(); } return remoteAddr; }

但是有个问题,用户每日的ip会变化……

更多详尽,参考此文章

转载请注明原文地址: https://www.6miu.com/read-1950401.html

最新回复(0)