HttpServletRequest接收requestBody的写法

2023-11-02 12:41:41 浏览数 (1)

代码语言:javascript复制
    public static String getStreamAsString(InputStream stream, String charset) throws IOException {
        try {
            Reader reader = new InputStreamReader(stream, charset);
            StringBuilder response = new StringBuilder();
            char[] buff = new char[1024];

            int read;
            while((read = reader.read(buff)) > 0) {
                response.append(buff, 0, read);
            }

            String var6 = response.toString();
            return var6;
        } finally {
            if (stream != null) {
                stream.close();
            }

        }
    }

代码语言:javascript复制
String body = WebUtils.getStreamAsString(request.getInputStream(), charset);

参考com.taobao.api.internal.util.WebUtils#getStreamAsString

0 人点赞