From 98118c2bf5343dde3dbf48c20bc8a0fd69cfedbd Mon Sep 17 00:00:00 2001 From: E1ED922C1E9526DD63272D7EC5C6CB77 <E1ED922C1E9526DD63272D7EC5C6CB77@i-search.com.cn> Date: 星期一, 14 十二月 2020 10:12:42 +0800 Subject: [PATCH] Merge branch 'master' of https://gitee.com/huoxiong/hx_common --- 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