I'm looking to make a post request with a base64 image. When I make the request, I get an error called "ERROR_IMAGE_SIZE_0"
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import java.io.*;
import java.net.*;
import java.util.Base64;
public class Main {
public static void main(String args[]) throws IOException {
File originalFile = new File("sec_token.php.png");
String encodedBase64 = null;
try {
FileInputStream fileInputStreamReader = new FileInputStream(originalFile);
byte[] bytes = new byte[(int)originalFile.length()];
fileInputStreamReader.read(bytes);
encodedBase64 = new String(Base64.getEncoder().encodeToString(bytes));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(encodedBase64);
HttpURLConnection con = (HttpURLConnection) new URL("http://2captcha.com/in.php?key=61f5d7a6cccc2db4e7c503a59f4f7e&method=base64&imginstructions="+encodedBase64).openConnection();
String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0";
System.out.println("User agent: " + USER_AGENT);
//add request header
con.setRequestMethod("POST");
con.setRequestProperty("Host", "2captcha.com");
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while((inputLine = in.readLine()) != null){
response.append(inputLine);
}
String res = response.toString();
System.out.println(res);
}
}