From fb766b5ff9f913561f76aa747c76eae5c3678589 Mon Sep 17 00:00:00 2001
From: qirong <2032486488@qq.com>
Date: 星期五, 08 十二月 2023 14:08:54 +0800
Subject: [PATCH] 三方同步

---
 ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/HttpUtils.java |   91 ++++++++++++++++++++++++++++++++-------------
 1 files changed, 65 insertions(+), 26 deletions(-)

diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/HttpUtils.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/HttpUtils.java
index 78e5ad3..5d1b2ea 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/HttpUtils.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/uitil/HttpUtils.java
@@ -1,5 +1,6 @@
 package org.dromara.system.uitil;
 
+import cn.hutool.json.JSON;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.methods.PostMethod;
@@ -13,11 +14,14 @@
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.util.EntityUtils;
 import org.dromara.common.oss.entity.SynchronousRequest;
+import org.dromara.common.oss.entity.VideoRequest;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.*;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 
 public class HttpUtils {
@@ -114,7 +118,7 @@
     }
 
     /**
-     * 涓婁紶鍚屾
+     * 涓婁紶鍚屾 瑙嗛涓撶綉
      * @param url
      * @param entity
      * @return
@@ -124,6 +128,7 @@
         org.apache.http.client.HttpClient httpClient = HttpClientBuilder.create().build();
         HttpPost httpPost = new HttpPost(url);
 
+        ContentType contentType = ContentType.create("multipart/form-data", StandardCharsets.UTF_8);
         MultipartEntityBuilder builder = MultipartEntityBuilder.create();
         builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
 
@@ -135,6 +140,65 @@
         builder.addTextBody("ossId", entity.getOssId(), ContentType.TEXT_PLAIN);
         builder.addTextBody("createBy", entity.getCreateBy(), ContentType.TEXT_PLAIN);
         builder.addTextBody("password", entity.getPassword(), ContentType.TEXT_PLAIN);
+        builder.addTextBody("fileName", entity.getFileName(), contentType);
+        builder.addTextBody("createTime", entity.getCreateTime(), ContentType.TEXT_PLAIN);
+
+        HttpEntity multipart = builder.build();
+        httpPost.setEntity(multipart);
+
+        HttpResponse response = httpClient.execute(httpPost);
+        String responseBody = EntityUtils.toString(response.getEntity());
+        System.out.println("Response: " + responseBody);
+        return responseBody;
+    }
+
+    /**
+     * 涓婁紶鍚屾 瑙嗛涓撶綉
+     * @param url
+     * @param entity
+     * @return
+     * @throws IOException
+     */
+    public static String sendPostRequest2(String url, VideoRequest entity) throws IOException {
+        org.apache.http.client.HttpClient httpClient = HttpClientBuilder.create().build();
+        HttpPost httpPost = new HttpPost(url);
+
+        ContentType contentType = ContentType.create("multipart/form-data", StandardCharsets.UTF_8);
+        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
+
+        // 娣诲姞MultipartFile鍙傛暟
+        builder.addBinaryBody("file", entity.getFile().getBytes(), ContentType.MULTIPART_FORM_DATA, entity.getFile().getOriginalFilename());
+
+        // 娣诲姞String鍙傛暟
+        builder.addTextBody("fileName", entity.getFileName(), contentType);
+
+        HttpEntity multipart = builder.build();
+        httpPost.setEntity(multipart);
+
+        HttpResponse response = httpClient.execute(httpPost);
+        String responseBody = EntityUtils.toString(response.getEntity());
+        System.out.println("Response: " + responseBody);
+        return responseBody;
+    }
+
+    /**
+     * 涓婁紶鍚屾2
+     * @param url
+     * @param entity
+     * @return
+     * @throws IOException
+     */
+    public static String sendPostRequestTwo(String url, SynchronousRequest entity) throws IOException {
+        org.apache.http.client.HttpClient httpClient = HttpClientBuilder.create().build();
+        HttpPost httpPost = new HttpPost(url);
+
+        ContentType contentType = ContentType.create("multipart/form-data", StandardCharsets.UTF_8);
+        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
+
+        // 娣诲姞MultipartFile鍙傛暟
+        builder.addBinaryBody("file", entity.getFile().getBytes(), ContentType.MULTIPART_FORM_DATA, entity.getFile().getOriginalFilename());
 
         HttpEntity multipart = builder.build();
         httpPost.setEntity(multipart);
@@ -151,31 +215,6 @@
 //     * @param parameter
      * @throws Exception
      */
-//    public static void sendDeleteRequest(String url, String parameter) throws Exception {
-//        // 鎷兼帴URL鍜屽弬鏁�
-//        String deleteUrl = url + "/" + parameter;
-//
-//        // 鍒涘缓URL瀵硅薄鍜孒ttpURLConnection瀵硅薄
-//        URL obj = new URL(deleteUrl);
-//        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
-//
-//        // 璁剧疆璇锋眰鏂规硶涓篋ELETE
-//        con.setRequestMethod("DELETE");
-//
-//        // 鍙戦�佽姹傚苟鑾峰彇鍝嶅簲
-//        int responseCode = con.getResponseCode();
-//        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
-//        String inputLine;
-//        StringBuffer response = new StringBuffer();
-//        while ((inputLine = in.readLine()) != null) {
-//            response.append(inputLine);
-//        }
-//        in.close();
-//
-//        // 鎵撳嵃鍝嶅簲缁撴灉
-//        System.out.println("Response Code : " + responseCode);
-//        System.out.println("Response : " + response.toString());
-//    }
     public static String sendDeleteRequest(String url, String ossId) throws IOException {
         org.apache.http.client.HttpClient httpClient = HttpClientBuilder.create().build();
         HttpPost httpPost = new HttpPost(url);

--
Gitblit v1.8.0