qirong
2023-12-04 9f6f07f1649f01258aaad541d9fa1dfca63641c0
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;
@@ -18,6 +19,8 @@
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 {
@@ -124,6 +127,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 +139,8 @@
        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(),);
        HttpEntity multipart = builder.build();
        httpPost.setEntity(multipart);
@@ -151,31 +157,6 @@
//     * @param parameter
     * @throws Exception
     */
//    public static void sendDeleteRequest(String url, String parameter) throws Exception {
//        // 拼接URL和参数
//        String deleteUrl = url + "/" + parameter;
//
//        // 创建URL对象和HttpURLConnection对象
//        URL obj = new URL(deleteUrl);
//        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//
//        // 设置请求方法为DELETE
//        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);