【Java】Spring的拦截器,在preHandle方法中获取request的请求体

@Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
                             Object handler) {
        StringBuffer url = request.getRequestURL();
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        String line = null;
        StringBuilder sb = new StringBuilder();
        try {
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        LOGGER.info("请求地址:{}, 请求参数:{}",url,sb.toString());
        return true;
    }

你可能感兴趣的:(Java)