package com.hx.util; import org.apache.commons.io.IOUtils; import javax.servlet.http.HttpServletRequest; import java.io.BufferedReader; import java.io.IOException; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; /** HttpServletRequestUtil 获取请求中的body * @author wangrenhuang * @Date 2021-10-19 */ public class HttpServletRequestUtil { /** * 获取bady * */ public static String getBody(HttpServletRequest request) { String wxMsgXml = null; if(request == null){ return wxMsgXml; } try{ wxMsgXml = IOUtils.toString(request.getInputStream(), "utf-8"); return wxMsgXml; }catch (Exception e){ wxMsgXml = null; } return wxMsgXml; } /** * * 获取请求头 * */ public static Map getHeader(HttpServletRequest request) { Enumeration enumeration = request.getHeaderNames(); Map map = new HashMap<>(16); StringBuffer headers = new StringBuffer(); while (enumeration.hasMoreElements()) { String name = enumeration.nextElement(); String value = request.getHeader(name); map.put(name,value); } return map; } }