以前用过手撕 HttpRequest 获取 Body、Params、Header 等 API 的时候,那叫一个复杂,自从用了 Hutool 神器后,发现如此的轻巧
// 获取请求头
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
Map<String, String> requestHeaderMap = ServletUtil.getHeaderMap(request);
// 获取请求体
Map<String, Object> requestParamMap = new LinkedHashMap<>();
String body = ServletUtil.getBody(request);
Map<String, String> params = ServletUtil.getParamMap(request);
更多【java-Java - Hutool 获取 HttpRequest:Header、Body、ParamMap 等利器】相关视频教程:www.yxfzedu.com