Quellcode durchsuchen

自动关闭 HttpResponse

JoeLazy vor 2 Monaten
Ursprung
Commit
5eea36e41b

+ 6 - 2
src/main/java/com/sundata/internalevaluation/calc/calcUnit/InterfaceCalcUnit.java

@@ -1,6 +1,7 @@
 package com.sundata.internalevaluation.calc.calcUnit;
 
 import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
 import cn.hutool.http.HttpUtil;
 import com.sundata.common.util.JsonUtil;
 import com.sundata.internalevaluation.calc.model.CalcException;
@@ -145,8 +146,11 @@ public class InterfaceCalcUnit extends CalcUnit {
             HttpRequest postRequest = HttpUtil.createPost(url);
             postRequest.addHeaders(headersMap);
             postRequest.body(JsonUtil.toJSONString(paramMap));
-            String responseStr = postRequest.execute().body();
-            thisResult.put(getCalcCode(), JsonUtil.jsonToMap(responseStr));
+            try (HttpResponse httpResponse = postRequest.execute()){
+                String responseStr = httpResponse.body();
+//                thisResult.put(getCalcCode(), JsonUtil.jsonToMap(responseStr));
+                thisResult.put(getCalcCode(), (responseStr));
+            }
         } else {
             // TODO Socket 请求
             throw new CalcException("目前仅支持http和https的请求");