fix pasting to hastebin

This commit is contained in:
Kermina Awad 2020-06-06 20:05:33 -04:00
parent d69c492577
commit e821611744
1 changed files with 8 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.Map;
/**
@ -43,14 +44,19 @@ public class HastebinPasteService implements PasteService {
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
wr = new OutputStreamWriter(conn.getOutputStream());
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
// hastebin needs a user-agent
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.flush();
String line;
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) {
responseString.append(line);
}