From ee972831c32537e5eb8972ed007136c6ba745757 Mon Sep 17 00:00:00 2001 From: ChenJiaHe <763432473@qq.com> Date: 星期一, 28 十二月 2020 16:25:30 +0800 Subject: [PATCH] 优化 --- src/main/java/com/hx/util/HttpUtil.java | 30 +++++++++++++++++++++++------- 1 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/hx/util/HttpUtil.java b/src/main/java/com/hx/util/HttpUtil.java index 26caf6f..f64532c 100644 --- a/src/main/java/com/hx/util/HttpUtil.java +++ b/src/main/java/com/hx/util/HttpUtil.java @@ -6,6 +6,8 @@ import org.springframework.web.multipart.MultipartFile; import javax.activation.MimetypesFileTypeMap; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; @@ -23,6 +25,27 @@ /**鍥炶溅鎹㈣,鐢ㄤ簬涓�琛岀殑缁撳熬*/ private static final String LINE_END = "\r\n"; + public static String getInputStream(HttpServletRequest request) throws Exception { + ServletInputStream stream = null; + BufferedReader reader = null; + StringBuffer sb = new StringBuffer(); + try { + stream = request.getInputStream(); + // 鑾峰彇鍝嶅簲 + reader = new BufferedReader(new InputStreamReader(stream)); + String line; + while ((line = reader.readLine()) != null) { + sb.append(line); + } + } catch (IOException e) { + //logger.error(e); + throw new RuntimeException("璇诲彇杩斿洖鏀粯鎺ュ彛鏁版嵁娴佸嚭鐜板紓甯革紒"); + } finally { + reader.close(); + } + //logger.info("杈撳叆娴佽繑鍥炵殑鍐呭锛�" + sb.toString()); + return sb.toString(); + } public static String post(String requestUrl, String accessToken, String params) throws Exception { @@ -162,13 +185,6 @@ // //System.out.println("HttpURLUtil:"+wxMsgXml); } catch (Exception e) { e.printStackTrace(); - obj = new JSONObject(); - try { - obj.put("status", 1); - obj.put("errMsg", e.getMessage()); - } catch (JSONException e1) { - e1.printStackTrace(); - } } finally { if (con != null) { con.disconnect(); -- Gitblit v1.8.0