From 11826e62d106adb19f996d8f239dbef47f1b3550 Mon Sep 17 00:00:00 2001
From: whyclxw <810412026@qq.com>
Date: 星期五, 18 十月 2024 08:43:24 +0800
Subject: [PATCH] 修改

---
 src/main/java/com/whyc/util/TestparamHttpUtil.java |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/whyc/util/TestparamHttpUtil.java b/src/main/java/com/whyc/util/TestparamHttpUtil.java
index 9c2e880..7d09b3f 100644
--- a/src/main/java/com/whyc/util/TestparamHttpUtil.java
+++ b/src/main/java/com/whyc/util/TestparamHttpUtil.java
@@ -1,23 +1,77 @@
 package com.whyc.util;
 
 import com.whyc.dto.ResultA200Dto;
+import com.whyc.dto.ResultActmDto;
 import org.springframework.http.*;
 import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestClientException;
 import org.springframework.web.client.RestTemplate;
 
 public class TestparamHttpUtil {
 
 
+
     //post璇锋眰浼犲叆form-data 鏍煎紡
-    public static Object postforform_data( RestTemplate restTemplate,String url,  MultiValueMap<String, Object> paramMap){
+    public static Object postforform_dataA200( RestTemplate restTemplate,String url,  MultiValueMap<String, Object> paramMap){
         HttpHeaders headers = new HttpHeaders();
         HttpMethod method = HttpMethod.POST;
         // 璁剧疆浠ヨ〃鍗曠殑鏂瑰紡鎻愪氦
         headers.add("Content-Type", MediaType.MULTIPART_FORM_DATA_VALUE);
         HttpEntity< MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(paramMap, headers);
-        ResponseEntity<String> response = restTemplate.exchange(url, method, requestEntity,String.class );
-        String results= response.getBody();
+        String results= null;
+        try {
+            ResponseEntity<String> response = restTemplate.exchange(url, method, requestEntity,String.class );
+            results = response.getBody();
+        } catch (RestClientException  e) {
+            results=" {\n" +
+                    "      \"code\": \"210\",\n" +
+                    "      \"msg\": \"failed to controll\",\n" +
+                    "      \"data\": null,\n" +
+                    "      \"count\": 0\n" +
+                    "    }";
+        }
+        if(results==null){
+            results=" {\n" +
+                    "      \"code\": \"0\",\n" +
+                    "      \"msg\": \"failed to controll\",\n" +
+                    "      \"data\": null,\n" +
+                    "      \"count\": 0\n" +
+                    "    }";
+        }
         Object dto= ActionUtil.getGson().fromJson(results, ResultA200Dto.class);
         return dto;
     }
+
+    //post璇锋眰浼犲叆form-data 鏍煎紡
+    public static Object postforform_dataActm( RestTemplate restTemplate,String url,  MultiValueMap<String, Object> paramMap){
+        HttpHeaders headers = new HttpHeaders();
+        HttpMethod method = HttpMethod.POST;
+        // 璁剧疆浠ヨ〃鍗曠殑鏂瑰紡鎻愪氦
+        headers.add("Content-Type", MediaType.MULTIPART_FORM_DATA_VALUE);
+        HttpEntity< MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(paramMap, headers);
+        String results= null;
+        try {
+            ResponseEntity<String> response = restTemplate.exchange(url, method, requestEntity,String.class );
+            results = response.getBody();
+        } catch (RestClientException e) {
+            results=" {\n" +
+                    "      \"code\": \"210\",\n" +
+                    "      \"msg\": \"failed to controll\",\n" +
+                    "      \"data\": null,\n" +
+                    "      \"count\": 0\n" +
+                    "    }";
+        }
+        if(results==null){
+            results=" {\n" +
+                    "      \"code\": \"0\",\n" +
+                    "      \"msg\": \"failed to controll\",\n" +
+                    "      \"data\": null,\n" +
+                    "      \"count\": 0\n" +
+                    "    }";
+        }
+        Object dto= ActionUtil.getGson().fromJson(results, ResultActmDto.class);
+        return dto;
+    }
+
+
 }
\ No newline at end of file

--
Gitblit v1.9.1