From 04b98c78e92c919108f2bd9836f49ba6adac1d4b Mon Sep 17 00:00:00 2001 From: FongMi Date: Wed, 19 Jul 2023 09:50:50 +0800 Subject: [PATCH] Fix js bug --- .../src/main/java/com/fongmi/quickjs/bean/Req.java | 12 ++++++------ .../main/java/com/fongmi/quickjs/method/Global.java | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/quickjs/src/main/java/com/fongmi/quickjs/bean/Req.java b/quickjs/src/main/java/com/fongmi/quickjs/bean/Req.java index 161e55b66..9b7f2046f 100644 --- a/quickjs/src/main/java/com/fongmi/quickjs/bean/Req.java +++ b/quickjs/src/main/java/com/fongmi/quickjs/bean/Req.java @@ -20,9 +20,9 @@ public class Req { @SerializedName("method") private String method; @SerializedName("body") - private String body; + private JsonElement body; @SerializedName("data") - private String data; + private JsonElement data; @SerializedName("headers") private JsonElement headers; @@ -46,12 +46,12 @@ public class Req { return TextUtils.isEmpty(method) ? "get" : method; } - public String getBody() { - return TextUtils.isEmpty(body) ? "" : body.trim(); + public JsonElement getBody() { + return body; } - public String getData() { - return TextUtils.isEmpty(data) ? "" : data.trim(); + public JsonElement getData() { + return data; } private JsonElement getHeaders() { diff --git a/quickjs/src/main/java/com/fongmi/quickjs/method/Global.java b/quickjs/src/main/java/com/fongmi/quickjs/method/Global.java index 6f0a61599..0da19efc3 100644 --- a/quickjs/src/main/java/com/fongmi/quickjs/method/Global.java +++ b/quickjs/src/main/java/com/fongmi/quickjs/method/Global.java @@ -161,7 +161,7 @@ public class Global { timer.schedule(new TimerTask() { @Override public void run() { - if (!executor.isShutdown()) executor.submit(() -> { func.call(); }); + if (!executor.isShutdown()) executor.submit(() -> {func.call();}); } }, delay); } @@ -183,8 +183,8 @@ public class Global { } private RequestBody getPostBody(Req req, String contentType) { - if (!req.getData().isEmpty()) return RequestBody.create(req.getData(), MediaType.get("application/json")); - if (!req.getBody().isEmpty() && contentType != null) return RequestBody.create(req.getBody(), MediaType.get(contentType)); + if (req.getData() != null) return RequestBody.create(gson.toJson(req.getData()), MediaType.get("application/json")); + if (req.getBody() != null && contentType != null) return RequestBody.create(gson.toJson(req.getBody()), MediaType.get(contentType)); return RequestBody.create("", null); }