獲取ip地址的方法:
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();? ? ? ?
? ? }?
獲取body請求體中的數(shù)據(jù)的方法:
用io去讀
BufferedReader reader = request.getReader();
? ? String str, wholeStr ="";
? ? while((str = reader.readLine()) != null){
? ? wholeStr += str;
? ? }
? ? JSONObject params = new JSONObject().parseObject(wholeStr);
然后params.get("xx")就可以直接獲取參數(shù)了 ?當(dāng)然請求體中的數(shù)據(jù)得是json格式