Last active
June 16, 2017 12:22
-
-
Save zekroTJA/7a6f21163104f7605dc89c58dc9ba8e0 to your computer and use it in GitHub Desktop.
Hastebin upload snippet
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
/** | |
* Method by StupPlayer (https://github.com/StupPlayer) | |
* @param data input as string | |
* @return hastebin paste URL / error message | |
*/ | |
public static String hastePost(String data) { | |
CloseableHttpClient client = HttpClientBuilder.create().build(); | |
HttpPost post = new HttpPost("https://hastebin.com/documents"); | |
try { | |
post.setEntity(new StringEntity(data)); | |
CloseableHttpResponse response = client.execute(post); | |
String result = EntityUtils.toString(response.getEntity()); | |
return "https://hastebin.com/" + new JsonParser().parse(result).getAsJsonObject().get("key").getAsString(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return "Unexpected error while posting!"; | |
} |
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
<dependency> | |
<groupId>org.apache.httpcomponents</groupId> | |
<artifactId>httpclient</artifactId> | |
<version>4.4</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.commons</groupId> | |
<artifactId>commons-lang3</artifactId> | |
<version>3.5</version> | |
</dependency> | |
<dependency> | |
<groupId>com.mashape.unirest</groupId> | |
<artifactId>unirest-java</artifactId> | |
<version>1.4.9</version> | |
</dependency> | |
<dependency> | |
<groupId>com.google.code.gson</groupId> | |
<artifactId>gson</artifactId> | |
<version>2.8.1</version> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment