Skip to content

Instantly share code, notes, and snippets.

@zekroTJA
Last active June 16, 2017 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zekroTJA/7a6f21163104f7605dc89c58dc9ba8e0 to your computer and use it in GitHub Desktop.
Save zekroTJA/7a6f21163104f7605dc89c58dc9ba8e0 to your computer and use it in GitHub Desktop.
Hastebin upload snippet
/**
* 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!";
}
<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