diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-06-25 17:12:12 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-06-25 17:12:12 +0800 |
commit | b1bc366e52cf719f0e3f01719fd787e7873baf84 (patch) | |
tree | 4c744c4829db830855e54269b1b14004d61e644e /utils | |
parent | ce4f287e9bce572bcb6512fd42d4b299ea846687 (diff) | |
download | SoopyV2-b1bc366e52cf719f0e3f01719fd787e7873baf84.tar.gz SoopyV2-b1bc366e52cf719f0e3f01719fd787e7873baf84.tar.bz2 SoopyV2-b1bc366e52cf719f0e3f01719fd787e7873baf84.zip |
+ changes
Diffstat (limited to 'utils')
-rw-r--r-- | utils/networkUtils.js | 20 |
1 files changed, 19 insertions, 1 deletions
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) { |