From b1bc366e52cf719f0e3f01719fd787e7873baf84 Mon Sep 17 00:00:00 2001 From: Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> Date: Sat, 25 Jun 2022 17:12:12 +0800 Subject: + changes --- utils/networkUtils.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'utils') diff --git a/utils/networkUtils.js b/utils/networkUtils.js index 0233ac0..31269fb 100644 --- a/utils/networkUtils.js +++ b/utils/networkUtils.js @@ -5,8 +5,9 @@ if (!global.networkUtilsThingSoopy) { let jCollectors = Java.type("java.util.stream.Collectors") let jBufferedReader = Java.type("java.io.BufferedReader") let jInputStreamReader = Java.type("java.io.InputStreamReader") + let jString = Java.type("java.lang.String") - function getUrlContent(theUrl, { userAgent = "Mozilla/5.0", includeConnection = false } = {}) { + function getUrlContent(theUrl, { userAgent = "Mozilla/5.0", includeConnection = false, postData = undefined } = {}) { if (global.soopyv2loggerthing) { global.soopyv2loggerthing.logMessage("Loading API: " + theUrl, 4) @@ -20,6 +21,23 @@ if (!global.networkUtilsThingSoopy) { let conn = new jURL(theUrl).openConnection() conn.setRequestProperty("User-Agent", userAgent) + if (postData) { + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/json"); + conn.setDoOutput(true); + + let jsonInputString = new jString(JSON.stringify(postData)) + + let os + try { + os = conn.getOutputStream() + input = jsonInputString.getBytes("utf-8"); + os.write(input, 0, input.length); + } finally { + os.close() + } + } + let stringData if (conn.getResponseCode() < 400) { -- cgit