java解析前端请求接口的全部入参

第一种:
public static String getRequestInput(HttpServletRequest request) {
        
        StringBuilder sb = new StringBuilder();
        boolean isFirst = true;
        @SuppressWarnings("unchecked")
        Enumeration<String> er = request.getParameterNames();
        while (er.hasMoreElements()) {
            String name = (String) er.nextElement();
            String value = request.getParameter(name);
            if (isFirst) {
                sb.append(name + "=" + value);
                isFirst = false;
            }
            else {
                if (value != null) {
                    sb.append("&" + name + "=" + value);
                }
                else {
                    sb.append("&" + name + "=");
                }
            }
        }
        return sb.toString();
    }
第二种:
 private String getRequestInput(HttpServletRequest request) {
        String inputLine;
        String a = "";
        try {
            while ((inputLine = request.getReader().readLine()) != null) {
                a += inputLine;
            }
            request.getReader().close();
        } catch (Exception e) {

            e.printStackTrace();
        }
        System.out.println(a);
        return a;
    }

 

posted @ 2018-09-20 10:31  宇枫  阅读(1695)  评论(0编辑  收藏  举报