houzhongjian
2024-07-23 a6de490948278991e47952e90671ddba4555e9a2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.iailab.module.data.framework.filter;
 
import groovy.util.logging.Slf4j;
 
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
 
@Slf4j
public class RequestReadUtils {
    /**
     * 读取请求流
     * @param request
     * @return
     */
    public static String read(HttpServletRequest request){
        try(BufferedReader reader = request.getReader()){
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            return sb.toString();
        }catch (Exception e){
            throw new RuntimeException("MyHttpServletRequestWrapper.RequestReadUtils.read 获取请求流异常");
        }
    }
}