From d891b53c27f2fa75ebe0976e9d296704bb263a0b Mon Sep 17 00:00:00 2001 From: hanpijun <1548749669@qq.com> Date: Wed, 11 Jun 2025 15:57:33 +0800 Subject: [PATCH] fix: Fix the NoSuchMethodError error that occurs when calling a post request without a request body when your project depends on OkHttp3.x (#373) --- .../pay/java/core/http/okhttp/OkHttpClientAdapter.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/wechat/pay/java/core/http/okhttp/OkHttpClientAdapter.java b/core/src/main/java/com/wechat/pay/java/core/http/okhttp/OkHttpClientAdapter.java index a47cec00..78669ffb 100644 --- a/core/src/main/java/com/wechat/pay/java/core/http/okhttp/OkHttpClientAdapter.java +++ b/core/src/main/java/com/wechat/pay/java/core/http/okhttp/OkHttpClientAdapter.java @@ -68,7 +68,7 @@ private RequestBody buildOkHttpRequestBody( com.wechat.pay.java.core.http.RequestBody wechatPayRequestBody) { if (wechatPayRequestBody == null) { // create an empty request body - return RequestBody.create("", null); + return createOkHttpEmptyRequestBody(); } if (wechatPayRequestBody instanceof JsonRequestBody) { return createOkHttpRequestBody(wechatPayRequestBody); @@ -95,6 +95,10 @@ private okhttp3.RequestBody createRequestBody(byte[] content, okhttp3.MediaType return okhttp3.RequestBody.create(mediaType, content); } + private RequestBody createOkHttpEmptyRequestBody() { + return createRequestBody("", null); + } + private RequestBody createOkHttpRequestBody( com.wechat.pay.java.core.http.RequestBody wechatPayRequestBody) { return createRequestBody(