@PostMapping("/test")
public void test(HttpServletRequest httpServletRequest) {
// 获取内容长度
int length = httpServletRequest.getContentLength();
// 新建缓存存放读取数据
byte[] buffer = new byte[length];
ServletInputStream in = null;
try {
in = httpServletRequest.getInputStream();
in.read(buffer, 0, length);
in.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != in) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
try {
log.info(new String(buffer, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
SpringBoot 项目通过 HttpServletRequest 获取 body 内容
最新推荐文章于 2024-02-27 16:41:13 发布