0
\$\begingroup\$

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);
    }
}
\$\endgroup\$
3
  • \$\begingroup\$ How do you get the error back? Is it from the site's API? \$\endgroup\$ Commented Feb 17, 2019 at 13:33
  • \$\begingroup\$ Yes, ERROR_ZERO_CAPTCHA_FILESIZE Image size is less than 100 bytes. Check the image file. \$\endgroup\$ Commented Feb 17, 2019 at 13:37
  • 1
    \$\begingroup\$ Wow, you ask inside a Game Development Focused Stack Exchange how to use a Captcha Solving Service correctly and Post your private API Key here... \$\endgroup\$ Commented Feb 22, 2019 at 14:03

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.