forked from 2captcha/2captcha-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGridBase64Example.java
More file actions
29 lines (21 loc) · 818 Bytes
/
GridBase64Example.java
File metadata and controls
29 lines (21 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package examples;
import com.twocaptcha.TwoCaptcha;
import com.twocaptcha.captcha.Grid;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Base64;
public class GridBase64Example {
public static void main(String[] args) throws Exception {
TwoCaptcha solver = new TwoCaptcha("YOUR_API_KEY");
byte[] bytes = Files.readAllBytes(Paths.get("src/main/resources/grid.jpg"));
String base64EncodedImage = Base64.getEncoder().encodeToString(bytes);
Grid captcha = new Grid();
captcha.setBase64(base64EncodedImage);
try {
solver.solve(captcha);
System.out.println("Captcha solved: " + captcha.getCode());
} catch (Exception e) {
System.out.println("Error occurred: " + e.getMessage());
}
}
}