2020-07-29 17:31:54 +00:00
|
|
|
package xyz.etztech.minealert;
|
|
|
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URLConnection;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
|
|
public class Webhook {
|
|
|
|
|
|
|
|
public static void send(String webhook, String embed) throws Exception {
|
|
|
|
URL url = new URL(webhook);
|
|
|
|
URLConnection con = url.openConnection();
|
|
|
|
HttpURLConnection http = (HttpURLConnection) con;
|
|
|
|
http.setRequestMethod("POST");
|
|
|
|
http.setDoOutput(true);
|
|
|
|
|
|
|
|
byte[] out = embed.getBytes(StandardCharsets.UTF_8);
|
|
|
|
int length = out.length;
|
|
|
|
http.setFixedLengthStreamingMode(length);
|
2020-07-29 19:34:28 +00:00
|
|
|
http.setRequestProperty("Content-Type", "application/json; utf-8");
|
|
|
|
http.setRequestProperty("User-Agent", "MineAlert Agent");
|
2020-07-29 17:31:54 +00:00
|
|
|
|
2020-07-29 19:34:28 +00:00
|
|
|
try (OutputStream os = http.getOutputStream()) {
|
|
|
|
os.write(out, 0, out.length);
|
|
|
|
}
|
2020-07-29 17:31:54 +00:00
|
|
|
}
|
|
|
|
}
|