mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-15 20:12:02 +01:00
fix pasting to hastebin
This commit is contained in:
parent
d69c492577
commit
e821611744
@ -9,6 +9,7 @@ import java.io.OutputStreamWriter;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,14 +44,19 @@ public class HastebinPasteService implements PasteService {
|
|||||||
URLConnection conn = url.openConnection();
|
URLConnection conn = url.openConnection();
|
||||||
conn.setDoOutput(true);
|
conn.setDoOutput(true);
|
||||||
|
|
||||||
wr = new OutputStreamWriter(conn.getOutputStream());
|
// hastebin needs a user-agent
|
||||||
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
conn.addRequestProperty("User-Agent", "placeholder");
|
||||||
|
// this isn't required, but is technically correct
|
||||||
|
conn.addRequestProperty("Content-Type", "text/plain; charset=utf-8");
|
||||||
|
|
||||||
|
wr = new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8.newEncoder());
|
||||||
wr.write(encodedData);
|
wr.write(encodedData);
|
||||||
wr.flush();
|
wr.flush();
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
StringBuilder responseString = new StringBuilder();
|
StringBuilder responseString = new StringBuilder();
|
||||||
|
// this has to be initialized AFTER the data has been flushed!
|
||||||
|
rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
responseString.append(line);
|
responseString.append(line);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user