Well, I wanted to know how to send an image of type BufferedImage
to a link using POST
method.
I'm using this code to send, but I'm not sure how to send this BufferedImage
.
public static String getImgurContent() throws Exception {
URL url;
url = new URL("https://api.imgur.com/3/image");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
BufferedImage img = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
String data = URLEncoder.encode("image", "UTF-8") + "=" + URLEncoder.encode("BUFFERED_IMAGE_AQUI", "UTF-8");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("Authorization", "Client-ID " + "00000000000");
conn.setRequestMethod("POST");
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();
}