aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java
diff options
context:
space:
mode:
authorSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2022-10-21 15:51:44 +0800
committerGitHub <noreply@github.com>2022-10-21 09:51:44 +0200
commit44fad457f0a066b0378b3cb615fd389d8d2a0850 (patch)
treecdf1c1efb35432e52c4448ed23152c50051148ed /src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java
parent280a89cdbf086e53bcd6985e1ddd48b6aa718087 (diff)
downloadnotenoughupdates-44fad457f0a066b0378b3cb615fd389d8d2a0850.tar.gz
notenoughupdates-44fad457f0a066b0378b3cb615fd389d8d2a0850.tar.bz2
notenoughupdates-44fad457f0a066b0378b3cb615fd389d8d2a0850.zip
Soopy networth option in pv (#303)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java
index 8c594911..7818c3c0 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java
@@ -33,6 +33,7 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
@@ -82,6 +83,8 @@ public class ApiUtil {
private String baseUrl = null;
private boolean shouldGunzip = false;
private String method = "GET";
+ private String postData = null;
+ private String postContentType = null;
public Request method(String method) {
this.method = method;
@@ -108,6 +111,12 @@ public class ApiUtil {
return this;
}
+ public Request postData(String contentType, String data) {
+ this.postContentType = contentType;
+ this.postData = data;
+ return this;
+ }
+
private CompletableFuture<URL> buildUrl() {
CompletableFuture<URL> fut = new CompletableFuture<>();
try {
@@ -140,6 +149,18 @@ public class ApiUtil {
conn.setConnectTimeout(10000);
conn.setReadTimeout(10000);
conn.setRequestProperty("User-Agent", USER_AGENT);
+ if (this.postContentType != null) {
+ conn.setRequestProperty("Content-Type", this.postContentType);
+ }
+ if (this.postData != null) {
+ conn.setDoOutput(true);
+ OutputStream os = conn.getOutputStream();
+ try {
+ os.write(this.postData.getBytes("utf-8"));
+ } finally {
+ os.close();
+ }
+ }
inputStream = conn.getInputStream();