直接取出 post 请求中的 json、得请求体参数、查看 post 请求参数

2022-04-13 15:54:56 浏览数 (1)

方法如下:

代码语言:javascript复制
       try{
            ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            HttpServletRequest request = requestAttributes.getRequest();

            StringBuffer sb = new StringBuffer() ;
            InputStream is = request.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String s = "" ;
            while((s=br.readLine())!=null){
                sb.append(s) ;
            }
            String result =sb.toString();
            log.info("nn ----------- 请求 json 为 :" result);
        }catch (Exception e){
            ... 
        }

0 人点赞