From 0cf5c56c81780f180a6bef9c51c065a874f53657 Mon Sep 17 00:00:00 2001 From: skosnt2019 <346403746@qq.com> Date: Tue, 17 Dec 2024 17:26:32 +0800 Subject: [PATCH 1/2] fix admin: The error occurs when testing the sandbox API, and the target method is not a POST request. --- .../java/org/apache/shenyu/admin/utils/HttpUtils.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java index e814fefc57f1..bfa6b79f1929 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java @@ -28,6 +28,7 @@ import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.ResponseBody; +import okhttp3.internal.http.HttpMethod; import okhttp3.logging.HttpLoggingInterceptor; import okhttp3.logging.HttpLoggingInterceptor.Level; import org.apache.commons.codec.digest.DigestUtils; @@ -220,15 +221,16 @@ public String request(final String url, final Map form, final Map header) throws IOException { + final Map header, HTTPMethod method) throws IOException { RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, json); Request.Builder requestBuilder = new Request.Builder() .url(url) - .post(body); + .method(method.value(), HttpMethod.requiresRequestBody(method.value()) ? body : null); addHeader(requestBuilder, header); Request request = requestBuilder.build(); @@ -305,7 +307,7 @@ public Response requestCall(final String url, final Map form, final M if (Objects.nonNull(files) && !files.isEmpty()) { return requestFile(url, form, header, files); } else if (isJsonRequest(header)) { - return requestJson(url, JsonUtils.toJson(form), header); + return requestJson(url, JsonUtils.toJson(form), header, method); } else { return requestForResponse(url, form, header, method); } From 82f45adaa3817f255d40fa654c7a72a7ebbd9b67 Mon Sep 17 00:00:00 2001 From: skosnt2019 <346403746@qq.com> Date: Mon, 23 Dec 2024 10:20:42 +0800 Subject: [PATCH 2/2] fix admin: Applied Checkstyle to HttpUtils file --- .../src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java index bfa6b79f1929..d82532897539 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java @@ -226,7 +226,7 @@ public String request(final String url, final Map form, final Map header, HTTPMethod method) throws IOException { + final Map header, final HTTPMethod method) throws IOException { RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, json); Request.Builder requestBuilder = new Request.Builder() .url(url)