From 727c442584fd8e3372c9961582a8ae936c83fa07 Mon Sep 17 00:00:00 2001 From: dzmitry-duboyski Date: Fri, 24 Jan 2025 20:23:27 +0400 Subject: [PATCH] Add UserAgent and Cookies support to reCAPTCHA method --- README.md | 2 ++ src/main/java/com/twocaptcha/captcha/ReCaptcha.java | 8 ++++++++ src/main/java/examples/ReCaptchaV2OptionsExample.java | 2 ++ src/test/java/com/twocaptcha/ReCaptchaTest.java | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 5086564..7fa2058 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,8 @@ captcha.setInvisible(true); captcha.setEnterprise(true); captcha.setAction("verify"); captcha.setProxy("HTTPS", "login:password@IP_address:PORT"); +captcha.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36"); +captcha.setCookies("KEY1:Value1;KEY2:Value2;"); ``` ### reCAPTCHA v3 diff --git a/src/main/java/com/twocaptcha/captcha/ReCaptcha.java b/src/main/java/com/twocaptcha/captcha/ReCaptcha.java index 678d4ab..996cd51 100644 --- a/src/main/java/com/twocaptcha/captcha/ReCaptcha.java +++ b/src/main/java/com/twocaptcha/captcha/ReCaptcha.java @@ -39,4 +39,12 @@ public void setData(String data) { params.put("data-s", data); } + public void setUserAgent(String userAgent) { + params.put("userAgent", userAgent); + } + + public void setCookies(String cookies) { + params.put("cookies", cookies); + } + } diff --git a/src/main/java/examples/ReCaptchaV2OptionsExample.java b/src/main/java/examples/ReCaptchaV2OptionsExample.java index 0ad4d73..1d8a3d1 100644 --- a/src/main/java/examples/ReCaptchaV2OptionsExample.java +++ b/src/main/java/examples/ReCaptchaV2OptionsExample.java @@ -21,6 +21,8 @@ public static void main(String[] args) { captcha.setData("foo"); captcha.setAction("verify"); captcha.setProxy("HTTPS", "login:password@IP_address:PORT"); + captcha.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36"); + captcha.setCookies("KEY1:Value1;KEY2:Value2;"); try { solver.solve(captcha); diff --git a/src/test/java/com/twocaptcha/ReCaptchaTest.java b/src/test/java/com/twocaptcha/ReCaptchaTest.java index 21f4061..6c2fb66 100644 --- a/src/test/java/com/twocaptcha/ReCaptchaTest.java +++ b/src/test/java/com/twocaptcha/ReCaptchaTest.java @@ -14,6 +14,8 @@ public void testV2() throws Exception { captcha.setInvisible(true); captcha.setEnterprise(true); captcha.setAction("verify"); + captcha.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36"); + captcha.setCookies("KEY1:Value1;KEY2:Value2;"); Map params = new HashMap<>(); params.put("method", "userrecaptcha"); @@ -22,6 +24,8 @@ public void testV2() throws Exception { params.put("invisible", "1"); params.put("enterprise", "1"); params.put("action", "verify"); + params.put("userAgent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36"); + params.put("cookies", "KEY1:Value1;KEY2:Value2;"); params.put("soft_id", "4581"); params.put("json", "0");