Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.pastebin.pastebinplugin;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.net.HttpURLConnection;
- import java.net.URL;
- /**
- * Send code to pastebin.com.
- * @author aNNiMON
- */
- public class PastebinSender {
- private static final String URL = "http://pastebin.com/api/api_post.php";
- /**
- * Send request to pastebin.
- * @param request @see http://pastebin.com/api
- * @return pasted url or error message.
- */
- public static String sendRequest(String request) {
- try {
- URL url = new URL(URL);
- HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
- httpConn.setRequestMethod("POST");
- httpConn.setInstanceFollowRedirects(false);
- httpConn.setDoOutput(true);
- httpConn.connect();
- OutputStreamWriter out = new OutputStreamWriter(httpConn.getOutputStream());
- out.write(request);
- out.flush();
- StringBuilder response = new StringBuilder();
- BufferedReader in = new BufferedReader( new InputStreamReader(httpConn.getInputStream()) );
- String line;
- while ((line = in.readLine()) != null) {
- response.append(line).append('\n');
- }
- in.close();
- return response.toString();
- } catch (Exception ex) {
- return "Error";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement