Created
September 20, 2018 14:42
-
-
Save FrostDelta123/6ac899dcd224249687adb183d3501967 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String paste(String urlParameters) { | |
HttpURLConnection connection = null; | |
try { | |
URL url = new URL(pasteURL); | |
connection = (HttpURLConnection) url.openConnection(); | |
connection.setRequestMethod("POST"); | |
connection.setDoInput(true); | |
connection.setDoOutput(true); | |
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream(), "UTF-8")); | |
wr.write(urlParameters); | |
wr.flush(); | |
wr.close(); | |
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); | |
String inputLine; | |
StringBuilder response = new StringBuilder(); | |
while ((inputLine = in.readLine()) != null) response.append(inputLine); | |
in.close(); | |
JsonElement json = new JsonParser().parse(response.toString()); | |
if (!json.isJsonObject()) throw new IOException("error"); | |
return json.getAsJsonObject().get("key").getAsString(); | |
} catch (IOException e) { | |
return null; | |
} finally { | |
if (connection == null) return null; | |
connection.disconnect(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment