String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
本文介绍了一种在Java Web应用中获取客户端真实IP地址的方法。通过检查HTTP请求头部的不同字段,如x-forwarded-for、Proxy-Client-IP和WL-Proxy-Client-IP等,最终确定客户端的真实IP地址。
197

被折叠的 条评论
为什么被折叠?



