From 2ed1199d48f7207f4a012c04f61e13ac1a8d5154 Mon Sep 17 00:00:00 2001 From: chenjiahe <763432473@qq.com> Date: 星期四, 16 六月 2022 10:27:44 +0800 Subject: [PATCH] 新增请求安全工具 --- src/main/java/com/hx/util/HttpServletRequestUtil.java | 36 +++++++++++++++--------------------- 1 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/hx/util/HttpServletRequestUtil.java b/src/main/java/com/hx/util/HttpServletRequestUtil.java index 9449030..ded443f 100644 --- a/src/main/java/com/hx/util/HttpServletRequestUtil.java +++ b/src/main/java/com/hx/util/HttpServletRequestUtil.java @@ -1,5 +1,7 @@ package com.hx.util; +import org.apache.commons.io.IOUtils; + import javax.servlet.http.HttpServletRequest; import java.io.BufferedReader; import java.io.IOException; @@ -13,34 +15,26 @@ */ public class HttpServletRequestUtil { - /* + /** * 鑾峰彇bady * */ public static String getBody(HttpServletRequest request) { - BufferedReader br = null; - StringBuilder sb = new StringBuilder(""); - String str ; - try { - br = request.getReader(); - while((str = br.readLine()) != null){ - sb.append(str); - } - } catch (IOException e) { - e.printStackTrace(); - }finally { - try { - if (null != br){ - br.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } + String wxMsgXml = null; + if(request == null){ + return wxMsgXml; } - return sb.toString(); + try{ + wxMsgXml = IOUtils.toString(request.getInputStream(), + "utf-8"); + return wxMsgXml; + }catch (Exception e){ + wxMsgXml = null; + } + return wxMsgXml; } - /* + /** * * 鑾峰彇璇锋眰澶� * */ -- Gitblit v1.8.0