Here you can find the source of getImgurContent(String clientID, byte[] image)
public static String getImgurContent(String clientID, byte[] image) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import javax.xml.bind.DatatypeConverter; public class Main { public static String getImgurContent(String clientID, byte[] image) throws IOException { String imageString = DatatypeConverter.printBase64Binary(image); URL url = new URL("https://api.imgur.com/3/image"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); String data = URLEncoder.encode("image", "UTF-8") + "=" + URLEncoder.encode(imageString, "UTF-8"); conn.setDoOutput(true);// w w w .j a v a 2 s . c om conn.setDoInput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Authorization", "Client-ID " + clientID); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.connect(); StringBuilder stb = new StringBuilder(); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = rd.readLine()) != null) { stb.append(line).append("\n"); } wr.close(); rd.close(); return stb.toString(); } }