Java获取请求ip地址详解编程语言

    public String checkIpAddress(HttpServletRequest request) {   
       
      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();    
       
      }    
       
      return ip;   
       
     }  

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/10209.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论