| | |
| | | ContentCachingRequestWrapper wrapper = (ContentCachingRequestWrapper) request; |
| | | byte[] content = wrapper.getContentAsByteArray(); |
| | | if (content.length > 0) { |
| | | return new String(content, wrapper.getCharacterEncoding()); |
| | | String encoding = wrapper.getCharacterEncoding() != null ? wrapper.getCharacterEncoding() : "UTF-8"; |
| | | return new String(content, encoding); |
| | | } |
| | | } |
| | | |
| | | // 如果不是包装器,尝试直接读取(可能会消耗请求体) |
| | | StringBuilder buffer = new StringBuilder(); |
| | | String line; |
| | | java.io.BufferedReader reader = request.getReader(); |
| | | while ((line = reader.readLine()) != null) { |
| | | buffer.append(line); |
| | | } |
| | | return buffer.toString(); |
| | | // 不从原始请求流读取,避免下游组件拿不到请求体导致 400 |
| | | return null; |
| | | } catch (Exception e) { |
| | | logger.warn("读取请求体失败", e); |
| | | return null; |