Browse Source

优化http请求

pull/229/head
chenzhihang 10 months ago
parent
commit
8270406d3c
2 changed files with 32 additions and 1 deletions
  1. +7
    -1
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/NewHttpUtils.java
  2. +25
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/HttpDeleteWithBody.java

+ 7
- 1
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/NewHttpUtils.java View File

@@ -1,5 +1,7 @@
package com.ruoyi.platform.utils;

import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.platform.vo.HttpDeleteWithBody;
import org.apache.http.HttpHost;
import org.apache.http.client.methods.*;
import org.apache.http.client.utils.URIBuilder;
@@ -80,7 +82,11 @@ public class NewHttpUtils {
}

public static String sendDeleteWithToken(String url, String param, String token, String body) throws Exception {
return sendRequest(new HttpDelete(), url, param, token, body);
if (StringUtils.isNotEmpty(body)) {
return sendRequest(new HttpDeleteWithBody(), url, param, token, body);
} else {
return sendRequest(new HttpDelete(), url, param, token, body);
}
}

public static String sendPatchWithToken(String url, String param, String token, String body) throws Exception {


+ 25
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/HttpDeleteWithBody.java View File

@@ -0,0 +1,25 @@
package com.ruoyi.platform.vo;

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;

import java.net.URI;

public class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase {
public static final String METHOD_NAME = "DELETE";

public HttpDeleteWithBody() {
}

public HttpDeleteWithBody(URI uri) {
this.setURI(uri);
}

public HttpDeleteWithBody(String uri) {
this.setURI(URI.create(uri));
}

@Override
public String getMethod() {
return METHOD_NAME;
}
}

Loading…
Cancel
Save