From 18f876d637cf1e9b0b264a4586e4a676a21f8166 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期五, 13 十一月 2026 10:30:46 +0800
Subject: [PATCH] 代码提交
---
ruoyi-common/src/main/java/com/ruoyi/common/utils/HttpUtil.java | 36 ++++++++++++++++++++++++++++++------
1 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/HttpUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/HttpUtil.java
index 0310368..2c73634 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/HttpUtil.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/HttpUtil.java
@@ -95,7 +95,26 @@
return httpClient;
}
+ /**
+ * json鐨刾ost璇锋眰锛堝彧鍏冲績鏄惁鎴愬姛锛岄潪200鐩存帴鎶涘紓甯革級
+ *
+ * @param url 璇锋眰url
+ * @param request 璇锋眰鎶ユ枃
+ * @return 鍥哄畾杩斿洖true锛坔ttp鐘舵�侀潪200浼氭姏HttpRequestException锛�
+ */
public static Boolean postJsonRequest(String url, String request) throws HttpRequestException {
+ postJsonRequestForString(url, request);
+ return true;
+ }
+
+ /**
+ * json鐨刾ost璇锋眰锛岃繑鍥炲搷搴旀姤鏂囧唴瀹癸紙鐢ㄤ簬闇�瑕佽В鏋愯繑鍥炵爜鐨勫満鏅紝濡備簯MAS鐭俊锛�
+ *
+ * @param url 璇锋眰url
+ * @param request 璇锋眰鎶ユ枃
+ * @return 鍝嶅簲鎶ユ枃鍐呭
+ */
+ public static String postJsonRequestForString(String url, String request) throws HttpRequestException {
Assert.hasLength(url, "璇锋眰url涓嶈兘涓虹┖瀛楃涓层��");
EntityEnclosingMethod httpMethod = new PostMethod(url);
@@ -132,8 +151,9 @@
String respJson = stringBuffer.toString();
// String respJson = httpMethod.getResponseBodyAsString();
if (resultCode == OK) {
- return true;
+ return respJson;
} else {
+ log.warn("銆恜ostJsonRequestForString銆戣姹傚け璐ワ紝url锛歿}锛岀姸鎬佺爜锛歿}锛屽搷搴旓細{}", url, resultCode, respJson);
throw new HttpRequestException(resultCode, respJson);
}
} catch (UnsupportedEncodingException e) {
@@ -395,14 +415,18 @@
// 鑾峰彇鍝嶅簲鐮�
int responseCode = connection.getResponseCode();
+ log.info("postFormRequest 鍝嶅簲鐮侊細{}锛寀rl锛歿}", responseCode, fullUrl);
- // 璇诲彇鍝嶅簲
+ // 璇诲彇鍝嶅簲锛堥潪200鏃秂rrorStream鍙兘涓簄ull锛岄伩鍏峃PE锛�
StringBuilder response = new StringBuilder();
- if (responseCode == HttpURLConnection.HTTP_OK) {
- reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- } else {
- reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
+ InputStream respStream = responseCode == HttpURLConnection.HTTP_OK
+ ? connection.getInputStream()
+ : connection.getErrorStream();
+ if (respStream == null) {
+ log.warn("postFormRequest 鍝嶅簲浣撲负绌猴紝鍝嶅簲鐮侊細{}锛寀rl锛歿}", responseCode, fullUrl);
+ return "";
}
+ reader = new BufferedReader(new InputStreamReader(respStream));
String line;
while ((line = reader.readLine()) != null) {
--
Gitblit v1.9.3