From 2fb3391255d4792b99073b0c22556b32a359d78a Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Tue, 12 Nov 2024 15:08:00 +0300 Subject: [PATCH 1/9] json response param --- TwoCaptcha/TwoCaptcha.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/TwoCaptcha/TwoCaptcha.cs b/TwoCaptcha/TwoCaptcha.cs index dca5786..e59d8cb 100644 --- a/TwoCaptcha/TwoCaptcha.cs +++ b/TwoCaptcha/TwoCaptcha.cs @@ -50,6 +50,11 @@ public class TwoCaptcha */ private bool lastCaptchaHasCallback; + /** + * JSON format response + */ + public int ExtendedResponse { get; set; } = 0; + /** * Network client */ From 2377ad5cd8ca6bacc4be7206bd0cb95f0ebc8865 Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Tue, 12 Nov 2024 18:53:31 +0300 Subject: [PATCH 2/9] ExtendedResponse --- TwoCaptcha.Examples/TextExample.cs | 2 +- TwoCaptcha/TwoCaptcha.cs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/TwoCaptcha.Examples/TextExample.cs b/TwoCaptcha.Examples/TextExample.cs index 8112dae..eb27868 100644 --- a/TwoCaptcha.Examples/TextExample.cs +++ b/TwoCaptcha.Examples/TextExample.cs @@ -8,7 +8,7 @@ public class TextExample { public TextExample(string apiKey) { - TwoCaptcha solver = new TwoCaptcha(apiKey); + TwoCaptcha solver = new TwoCaptcha(apiKey, 1); Text captcha = new Text("If tomorrow is Saturday, what day is today?"); diff --git a/TwoCaptcha/TwoCaptcha.cs b/TwoCaptcha/TwoCaptcha.cs index e59d8cb..8003250 100644 --- a/TwoCaptcha/TwoCaptcha.cs +++ b/TwoCaptcha/TwoCaptcha.cs @@ -78,6 +78,12 @@ public TwoCaptcha(string apiKey) : this() ApiKey = apiKey; } + public TwoCaptcha(string apiKey, int extendedResponse) : this() + { + ApiKey = apiKey; + ExtendedResponse = extendedResponse; + } + /** * @param apiClient */ @@ -213,6 +219,7 @@ public async Task GetResult(String id) var parameters = new Dictionary(); parameters["action"] = "get"; parameters["id"] = id; + parameters["json"] = ExtendedResponse.ToString(); string response = await Res(parameters); @@ -300,6 +307,7 @@ private async Task Res(Dictionary parameters) private void SendAttachDefaultParameters(Dictionary parameters) { parameters["key"] = ApiKey; + parameters["json"] = ExtendedResponse.ToString(); if (Callback != null) { From 9c9cc40a926d9e8eeafa3c67bdd4c1f8ec0b205a Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Wed, 13 Nov 2024 09:16:37 +0300 Subject: [PATCH 3/9] getId from json, string --- TwoCaptcha.Examples/TextExample.cs | 2 +- TwoCaptcha/TwoCaptcha.cs | 48 +++++++++++++++++++++++++++++- TwoCaptcha/TwoCaptcha.csproj | 3 ++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/TwoCaptcha.Examples/TextExample.cs b/TwoCaptcha.Examples/TextExample.cs index eb27868..e049078 100644 --- a/TwoCaptcha.Examples/TextExample.cs +++ b/TwoCaptcha.Examples/TextExample.cs @@ -8,7 +8,7 @@ public class TextExample { public TextExample(string apiKey) { - TwoCaptcha solver = new TwoCaptcha(apiKey, 1); + TwoCaptcha solver = new TwoCaptcha(apiKey/*, 1*/); Text captcha = new Text("If tomorrow is Saturday, what day is today?"); diff --git a/TwoCaptcha/TwoCaptcha.cs b/TwoCaptcha/TwoCaptcha.cs index 8003250..7caf70c 100644 --- a/TwoCaptcha/TwoCaptcha.cs +++ b/TwoCaptcha/TwoCaptcha.cs @@ -7,6 +7,10 @@ using TwoCaptcha.Captcha; using TwoCaptcha.Exceptions; using TimeoutException = TwoCaptcha.Exceptions.TimeoutException; +using System.Xml.Linq; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; +using System.Reflection; namespace TwoCaptcha { @@ -52,7 +56,7 @@ public class TwoCaptcha /** * JSON format response - */ + */ public int ExtendedResponse { get; set; } = 0; /** @@ -181,6 +185,45 @@ private long CurrentTime() return Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds); } + private string getCaptchaId(string response)/* throws ApiException*/ + { + try + { + //string source = "{\r\n \"id\": \"100000280905615\", \r\n \"name\": \"Jerard Jones\", \r\n \"first_name\": \"Jerard\", \r\n \"last_name\": \"Jones\", \r\n \"link\": \"https://www.facebook.com/Jerard.Jones\", \r\n \"username\": \"Jerard.Jones\", \r\n \"gender\": \"female\", \r\n \"locale\": \"en_US\"\r\n}"; + dynamic jsonObject = JObject.Parse(response); + //Console.WriteLine(data.id); + + //JSONObject jsonObject = new JSONObject(response); + string requestVal = jsonObject.request; + + if (requestVal.Equals("CAPCHA_NOT_READY")) + { + return null; + } + + return requestVal; + + } + catch (JsonException) + { + + if (response.Equals("CAPCHA_NOT_READY")) + { + return null; + } + + string responseStatus = response.Substring(0, 3); + + if (!responseStatus.Equals("OK|")) + { + throw new ApiException("Cannot recognise api response (" + response + ")"); + } + + return response.Substring(3); + } + } + + /** * Sends captcha to '/in.php', and returns its `id` * @@ -199,12 +242,15 @@ public async Task Send(Captcha.Captcha captcha) string response = await apiClient.In(parameters, files); + return getCaptchaId(response); + /* if (!response.StartsWith("OK|")) { throw new ApiException("Cannot recognise api response (" + response + ")"); } return response.Substring(3); + */ } /** diff --git a/TwoCaptcha/TwoCaptcha.csproj b/TwoCaptcha/TwoCaptcha.csproj index 45bd3c4..6835cc7 100644 --- a/TwoCaptcha/TwoCaptcha.csproj +++ b/TwoCaptcha/TwoCaptcha.csproj @@ -14,4 +14,7 @@ + + + \ No newline at end of file From 03e4b9a465126831d396e3b36276ef0a4c664cfe Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Thu, 14 Nov 2024 09:35:34 +0300 Subject: [PATCH 4/9] handleResponse --- TwoCaptcha.Examples/TextExample.cs | 2 +- TwoCaptcha/TwoCaptcha.cs | 51 ++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/TwoCaptcha.Examples/TextExample.cs b/TwoCaptcha.Examples/TextExample.cs index e049078..eb27868 100644 --- a/TwoCaptcha.Examples/TextExample.cs +++ b/TwoCaptcha.Examples/TextExample.cs @@ -8,7 +8,7 @@ public class TextExample { public TextExample(string apiKey) { - TwoCaptcha solver = new TwoCaptcha(apiKey/*, 1*/); + TwoCaptcha solver = new TwoCaptcha(apiKey, 1); Text captcha = new Text("If tomorrow is Saturday, what day is today?"); diff --git a/TwoCaptcha/TwoCaptcha.cs b/TwoCaptcha/TwoCaptcha.cs index 7caf70c..e0ce20f 100644 --- a/TwoCaptcha/TwoCaptcha.cs +++ b/TwoCaptcha/TwoCaptcha.cs @@ -185,15 +185,12 @@ private long CurrentTime() return Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds); } - private string getCaptchaId(string response)/* throws ApiException*/ + private string getCaptchaId(string response) { try { - //string source = "{\r\n \"id\": \"100000280905615\", \r\n \"name\": \"Jerard Jones\", \r\n \"first_name\": \"Jerard\", \r\n \"last_name\": \"Jones\", \r\n \"link\": \"https://www.facebook.com/Jerard.Jones\", \r\n \"username\": \"Jerard.Jones\", \r\n \"gender\": \"female\", \r\n \"locale\": \"en_US\"\r\n}"; dynamic jsonObject = JObject.Parse(response); - //Console.WriteLine(data.id); - - //JSONObject jsonObject = new JSONObject(response); + string requestVal = jsonObject.request; if (requestVal.Equals("CAPCHA_NOT_READY")) @@ -223,6 +220,40 @@ private string getCaptchaId(string response)/* throws ApiException*/ } } + private string handleResponse(string response) + { + try + { + dynamic jsonObject = JObject.Parse(response); + + string requestVal = jsonObject.request; + + if (requestVal.Equals("CAPCHA_NOT_READY")) + { + return null; + } + + return JsonConvert.ToString(jsonObject); + + } + catch (JsonException) + { + + if (response.Equals("CAPCHA_NOT_READY")) + { + return null; + } + + string responseStatus = response.Substring(0, 3); + + if (!responseStatus.Equals("OK|")) + { + throw new ApiException("Cannot recognise api response (" + response + ")"); + } + + return response.Substring(3); + } + } /** * Sends captcha to '/in.php', and returns its `id` @@ -267,9 +298,11 @@ public async Task GetResult(String id) parameters["id"] = id; parameters["json"] = ExtendedResponse.ToString(); - string response = await Res(parameters); + string responseStr = await Res(parameters); + + return handleResponse(responseStr); - if (response.Equals("CAPCHA_NOT_READY")) + /*if (response.Equals("CAPCHA_NOT_READY")) { return null; } @@ -279,9 +312,9 @@ public async Task GetResult(String id) throw new ApiException("Cannot recognise api response (" + response + ")"); } - return response.Substring(3); + return response.Substring(3);*/ } - + /** * Gets account's balance * From 4f6f02beec1326a9af5b5a0373d4d123f868c3e0 Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Fri, 15 Nov 2024 09:42:58 +0300 Subject: [PATCH 5/9] Cleanup --- TwoCaptcha/TwoCaptcha.cs | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/TwoCaptcha/TwoCaptcha.cs b/TwoCaptcha/TwoCaptcha.cs index e0ce20f..c67cae5 100644 --- a/TwoCaptcha/TwoCaptcha.cs +++ b/TwoCaptcha/TwoCaptcha.cs @@ -1,16 +1,13 @@ -using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; using System.Collections.Generic; -using System.IO; using System.Globalization; -using System.Threading; +using System.IO; using System.Threading.Tasks; using TwoCaptcha.Captcha; using TwoCaptcha.Exceptions; using TimeoutException = TwoCaptcha.Exceptions.TimeoutException; -using System.Xml.Linq; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json; -using System.Reflection; namespace TwoCaptcha { @@ -274,14 +271,6 @@ public async Task Send(Captcha.Captcha captcha) string response = await apiClient.In(parameters, files); return getCaptchaId(response); - /* - if (!response.StartsWith("OK|")) - { - throw new ApiException("Cannot recognise api response (" + response + ")"); - } - - return response.Substring(3); - */ } /** @@ -301,18 +290,6 @@ public async Task GetResult(String id) string responseStr = await Res(parameters); return handleResponse(responseStr); - - /*if (response.Equals("CAPCHA_NOT_READY")) - { - return null; - } - - if (!response.StartsWith("OK|")) - { - throw new ApiException("Cannot recognise api response (" + response + ")"); - } - - return response.Substring(3);*/ } /** From c63e9d1b2af7c29b69d03e488ccec2d1e0184652 Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Fri, 15 Nov 2024 10:28:49 +0300 Subject: [PATCH 6/9] readme --- README.md | 7 +++++-- TwoCaptcha.Examples/HCaptchaExample.cs | 1 + TwoCaptcha.Tests/AbstractWrapperTestCase.cs | 3 ++- TwoCaptcha.Tests/YandexTest.cs | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 37af3ea..d2cd1a6 100644 --- a/README.md +++ b/README.md @@ -72,17 +72,19 @@ solver.Callback = "https://your.site/result-receiver"; solver.DefaultTimeout = 120; solver.RecaptchaTimeout = 600; solver.PollingInterval = 10; +solver.ExtendedResponse = 1; ``` ### TwoCaptcha instance options | Option | Default value | Description | | ---------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | -| softId | 4582 | your software ID obtained after publishing in [2captcha sofware catalog] | +| softId | 4582 | your software ID obtained after publishing in [2captcha sofware catalog] | | callback | - | URL of your web-sever that receives the captcha recognition result. The URl should be first registered in [pingback settings] of your account | | defaultTimeout | 120 | Polling timeout in seconds for all captcha types except reCAPTCHA. Defines how long the module tries to get the answer from `res.php` API endpoint | | recaptchaTimeout | 600 | Polling timeout for reCAPTCHA in seconds. Defines how long the module tries to get the answer from `res.php` API endpoint | | pollingInterval | 10 | Interval in seconds between requests to `res.php` API endpoint, setting values less than 5 seconds is not recommended | +| json | 0 | Json or String format response from `res.php` API endpoint, extendedResponse = 1 returns JSON format response | > **IMPORTANT:** once `Callback` is defined for `TwoCaptcha` instance, all methods return only the captcha ID and DO NOT poll the API to get the result. The result will be sent to the callback URL. To get the answer manually use [getResult method](#send--getresult) @@ -240,7 +242,8 @@ captcha.SetUrl("https://mysite.com/captcha.html"); [API method description.](https://2captcha.com/2captcha-api#solving_hcaptcha) -Use this method to solve hCaptcha challenge. Returns a token to bypass captcha. +Use this method to solve hCaptcha challenge. Returns a token to bypass captcha. +Use 'ExtendedResponse' to get respKey and useragent in captcha answer. ```csharp HCaptcha captcha = new HCaptcha(); diff --git a/TwoCaptcha.Examples/HCaptchaExample.cs b/TwoCaptcha.Examples/HCaptchaExample.cs index 00ece48..ad67036 100644 --- a/TwoCaptcha.Examples/HCaptchaExample.cs +++ b/TwoCaptcha.Examples/HCaptchaExample.cs @@ -9,6 +9,7 @@ public class HCaptchaExample public HCaptchaExample(string apiKey) { TwoCaptcha solver = new TwoCaptcha(apiKey); + solver.ExtendedResponse = 1; HCaptcha captcha = new HCaptcha(); captcha.SetSiteKey("c0421d06-b92e-47fc-ab9a-5caa43c04538"); diff --git a/TwoCaptcha.Tests/AbstractWrapperTestCase.cs b/TwoCaptcha.Tests/AbstractWrapperTestCase.cs index b77f645..5983b07 100644 --- a/TwoCaptcha.Tests/AbstractWrapperTestCase.cs +++ b/TwoCaptcha.Tests/AbstractWrapperTestCase.cs @@ -26,6 +26,7 @@ Dictionary files string apiKey = "API_KEY"; string captchaId = "123"; string code = "2763"; + string json = "0"; parameters["key"] = apiKey; @@ -33,7 +34,7 @@ Dictionary files resParameters["action"] = "get"; resParameters["id"] = captchaId; resParameters["key"] = apiKey; - + resParameters["json"] = json; var apiClientMock = new Mock(); apiClientMock diff --git a/TwoCaptcha.Tests/YandexTest.cs b/TwoCaptcha.Tests/YandexTest.cs index 9b0cbfe..4d24089 100644 --- a/TwoCaptcha.Tests/YandexTest.cs +++ b/TwoCaptcha.Tests/YandexTest.cs @@ -20,6 +20,7 @@ public async Task TestAllOptions() parameters["sitekey"] = "Y5Lh0tiycconMJGsFd3EbbuNKSp1yaZESUOIHfeV"; parameters["pageurl"] = "https://rutube.ru"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } From 32f2316ad409dcc5a94e802c44dbf4992382e1e1 Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Tue, 19 Nov 2024 12:33:43 +0300 Subject: [PATCH 7/9] tests updated --- TwoCaptcha.Tests/AbstractWrapperTestCase.cs | 5 +++-- TwoCaptcha.Tests/AmazonWafTest.cs | 1 + TwoCaptcha.Tests/AtbCAPTCHATest.cs | 1 + TwoCaptcha.Tests/AudioTest.cs | 1 + TwoCaptcha.Tests/CanvasTest.cs | 3 +++ TwoCaptcha.Tests/CapyTest.cs | 2 +- TwoCaptcha.Tests/CoordinatesTest.cs | 4 ++++ TwoCaptcha.Tests/CutcaptchaTest.cs | 1 + TwoCaptcha.Tests/CyberSiARATest.cs | 1 + TwoCaptcha.Tests/DataDomeTest.cs | 1 + TwoCaptcha.Tests/FriendlyCaptchaTest.cs | 1 + TwoCaptcha.Tests/FunCaptchaTest.cs | 1 + TwoCaptcha.Tests/GeeTestTest.cs | 1 + TwoCaptcha.Tests/GeeTestV4Test.cs | 1 + TwoCaptcha.Tests/GridTest.cs | 4 ++++ TwoCaptcha.Tests/HCaptchaTest.cs | 1 + TwoCaptcha.Tests/KeyCaptchaTest.cs | 1 + TwoCaptcha.Tests/LeminTest.cs | 1 + TwoCaptcha.Tests/MTCaptchaTest.cs | 1 + TwoCaptcha.Tests/NormalTest.cs | 4 ++++ TwoCaptcha.Tests/ReCaptchaTest.cs | 2 ++ TwoCaptcha.Tests/RotateTest.cs | 2 +- TwoCaptcha.Tests/TencentTest.cs | 1 + TwoCaptcha.Tests/TextTest.cs | 3 +++ TwoCaptcha.Tests/TurnstileTest.cs | 1 + 25 files changed, 41 insertions(+), 4 deletions(-) diff --git a/TwoCaptcha.Tests/AbstractWrapperTestCase.cs b/TwoCaptcha.Tests/AbstractWrapperTestCase.cs index 5983b07..93f706f 100644 --- a/TwoCaptcha.Tests/AbstractWrapperTestCase.cs +++ b/TwoCaptcha.Tests/AbstractWrapperTestCase.cs @@ -33,8 +33,8 @@ Dictionary files var resParameters = new Dictionary(); resParameters["action"] = "get"; resParameters["id"] = captchaId; - resParameters["key"] = apiKey; resParameters["json"] = json; + resParameters["key"] = apiKey; var apiClientMock = new Mock(); apiClientMock @@ -49,7 +49,7 @@ Dictionary files solver.SetApiClient(apiClientMock.Object); await solver.Solve(captcha); - + apiClientMock.Verify(ac => ac.In( It.Is>(actual => ParametersAreSame(parameters, actual)), It.Is>(actual => FilesAreSame(files, actual)) @@ -57,6 +57,7 @@ Dictionary files Assert.AreEqual(captchaId, captcha.Id); Assert.AreEqual(code, captcha.Code); + } private bool ParametersAreSame(Dictionary expected, Dictionary actual) diff --git a/TwoCaptcha.Tests/AmazonWafTest.cs b/TwoCaptcha.Tests/AmazonWafTest.cs index 31a2858..fd884f5 100644 --- a/TwoCaptcha.Tests/AmazonWafTest.cs +++ b/TwoCaptcha.Tests/AmazonWafTest.cs @@ -24,6 +24,7 @@ public async Task TestAllOptions() parameters["context"] = "test_iv"; parameters["iv"] = "test_context"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } diff --git a/TwoCaptcha.Tests/AtbCAPTCHATest.cs b/TwoCaptcha.Tests/AtbCAPTCHATest.cs index 510a85b..caddd10 100644 --- a/TwoCaptcha.Tests/AtbCAPTCHATest.cs +++ b/TwoCaptcha.Tests/AtbCAPTCHATest.cs @@ -22,6 +22,7 @@ public async Task TestAllOptions() parameters["api_server"] = "https://cap.aisecurius.com"; parameters["pageurl"] = "https://www.example.com/"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(atbCAPTCHA, parameters); } diff --git a/TwoCaptcha.Tests/AudioTest.cs b/TwoCaptcha.Tests/AudioTest.cs index b1ae81f..edf4a68 100644 --- a/TwoCaptcha.Tests/AudioTest.cs +++ b/TwoCaptcha.Tests/AudioTest.cs @@ -28,6 +28,7 @@ public async Task TestAllParameters() parameters["lang"] = "en"; parameters["body"] = base64EncodedImage; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); diff --git a/TwoCaptcha.Tests/CanvasTest.cs b/TwoCaptcha.Tests/CanvasTest.cs index 2e256d2..8523f0c 100644 --- a/TwoCaptcha.Tests/CanvasTest.cs +++ b/TwoCaptcha.Tests/CanvasTest.cs @@ -31,6 +31,7 @@ public async Task TestSingleFile() parameters["canvas"] = "1"; parameters["textinstructions"] = hintText; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; var files = new Dictionary(); files["file"] = image; @@ -52,6 +53,7 @@ public async Task TestBase64() parameters["body"] = "..."; parameters["textinstructions"] = hintText; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } @@ -79,6 +81,7 @@ public async Task TestAllParameters() parameters["lang"] = "en"; parameters["textinstructions"] = hintText; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; var files = new Dictionary(); files["file"] = image; diff --git a/TwoCaptcha.Tests/CapyTest.cs b/TwoCaptcha.Tests/CapyTest.cs index 819cd33..0f28531 100644 --- a/TwoCaptcha.Tests/CapyTest.cs +++ b/TwoCaptcha.Tests/CapyTest.cs @@ -22,7 +22,7 @@ public async Task TestAllOptions() parameters["pageurl"] = "http://mysite.com/"; parameters["api_server"] = "https://myapiserver.com/"; parameters["soft_id"] = "4582"; - + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } diff --git a/TwoCaptcha.Tests/CoordinatesTest.cs b/TwoCaptcha.Tests/CoordinatesTest.cs index 5bb80a4..70ece94 100644 --- a/TwoCaptcha.Tests/CoordinatesTest.cs +++ b/TwoCaptcha.Tests/CoordinatesTest.cs @@ -25,6 +25,7 @@ public async Task TestSingleFile() parameters["method"] = "post"; parameters["coordinatescaptcha"] = "1"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; var files = new Dictionary(); files["file"] = image; @@ -44,6 +45,7 @@ public async Task TestSingleFileParameter() parameters["method"] = "post"; parameters["coordinatescaptcha"] = "1"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; var files = new Dictionary(); files["file"] = image; @@ -62,6 +64,7 @@ public async Task TestBase64() parameters["coordinatescaptcha"] = "1"; parameters["body"] = "..."; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } @@ -84,6 +87,7 @@ public async Task TestAllParameters() parameters["lang"] = "en"; parameters["textinstructions"] = hintText; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; var files = new Dictionary(); files["file"] = image; diff --git a/TwoCaptcha.Tests/CutcaptchaTest.cs b/TwoCaptcha.Tests/CutcaptchaTest.cs index 64c8a90..3751c6b 100644 --- a/TwoCaptcha.Tests/CutcaptchaTest.cs +++ b/TwoCaptcha.Tests/CutcaptchaTest.cs @@ -21,6 +21,7 @@ public async Task TestAllOptions() parameters["pageurl"] = "https://example.cc/foo/bar.html"; parameters["api_key"] = "SAb83IIB"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(cutcaptcha, parameters); } diff --git a/TwoCaptcha.Tests/CyberSiARATest.cs b/TwoCaptcha.Tests/CyberSiARATest.cs index 701c364..8f1f2e0 100644 --- a/TwoCaptcha.Tests/CyberSiARATest.cs +++ b/TwoCaptcha.Tests/CyberSiARATest.cs @@ -21,6 +21,7 @@ public async Task TestAllOptions() parameters["pageurl"] = "https://demo.mycybersiara.com/"; parameters["userAgent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(cyberSiARA, parameters); } diff --git a/TwoCaptcha.Tests/DataDomeTest.cs b/TwoCaptcha.Tests/DataDomeTest.cs index 501e406..3648450 100644 --- a/TwoCaptcha.Tests/DataDomeTest.cs +++ b/TwoCaptcha.Tests/DataDomeTest.cs @@ -28,6 +28,7 @@ public async Task TestAllOptions() parameters["proxytype"] = "http"; parameters["userAgent"] = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Mobile Safari/537.3"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(dataDome, parameters); } diff --git a/TwoCaptcha.Tests/FriendlyCaptchaTest.cs b/TwoCaptcha.Tests/FriendlyCaptchaTest.cs index 778be99..6ee3e47 100644 --- a/TwoCaptcha.Tests/FriendlyCaptchaTest.cs +++ b/TwoCaptcha.Tests/FriendlyCaptchaTest.cs @@ -20,6 +20,7 @@ public async Task TestAllOptions() parameters["sitekey"] = "2FZFEVS1FZCGQ9"; parameters["pageurl"] = "https://www.site.com/page/"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } diff --git a/TwoCaptcha.Tests/FunCaptchaTest.cs b/TwoCaptcha.Tests/FunCaptchaTest.cs index 042c783..1bcef91 100644 --- a/TwoCaptcha.Tests/FunCaptchaTest.cs +++ b/TwoCaptcha.Tests/FunCaptchaTest.cs @@ -26,6 +26,7 @@ public async Task TestAllOptions() parameters["userAgent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"; parameters["data[anyKey]"] = "anyStringValue"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } diff --git a/TwoCaptcha.Tests/GeeTestTest.cs b/TwoCaptcha.Tests/GeeTestTest.cs index 7e3733c..e5fe140 100644 --- a/TwoCaptcha.Tests/GeeTestTest.cs +++ b/TwoCaptcha.Tests/GeeTestTest.cs @@ -24,6 +24,7 @@ public async Task TestAllOptions() parameters["challenge"] = "69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC"; parameters["pageurl"] = "https://launches.endclothing.com/distil_r_captcha.html"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } diff --git a/TwoCaptcha.Tests/GeeTestV4Test.cs b/TwoCaptcha.Tests/GeeTestV4Test.cs index 0c69af1..523b0ff 100644 --- a/TwoCaptcha.Tests/GeeTestV4Test.cs +++ b/TwoCaptcha.Tests/GeeTestV4Test.cs @@ -22,6 +22,7 @@ public async Task TestAllOptions() parameters["challenge"] = "12345678abc90123d45678ef90123a456b"; parameters["pageurl"] = "https://mysite.com/captcha.html"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } diff --git a/TwoCaptcha.Tests/GridTest.cs b/TwoCaptcha.Tests/GridTest.cs index 14e1650..2907f13 100644 --- a/TwoCaptcha.Tests/GridTest.cs +++ b/TwoCaptcha.Tests/GridTest.cs @@ -24,6 +24,7 @@ public async Task TestSingleFile() parameters["method"] = "post"; parameters["recaptcha"] = "1"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; var files = new Dictionary(); files["file"] = image; @@ -43,6 +44,7 @@ public async Task TestSingleFileParameter() parameters["method"] = "post"; parameters["recaptcha"] = "1"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; var files = new Dictionary(); files["file"] = image; @@ -61,6 +63,7 @@ public async Task TestBase64() parameters["body"] = "..."; parameters["recaptcha"] = "1"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } @@ -91,6 +94,7 @@ public async Task TestAllParameters() parameters["lang"] = "en"; parameters["textinstructions"] = hintText; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; var files = new Dictionary(); files["file"] = image; diff --git a/TwoCaptcha.Tests/HCaptchaTest.cs b/TwoCaptcha.Tests/HCaptchaTest.cs index faff925..7d7ae56 100644 --- a/TwoCaptcha.Tests/HCaptchaTest.cs +++ b/TwoCaptcha.Tests/HCaptchaTest.cs @@ -22,6 +22,7 @@ public async Task TestAllOptions() parameters["pageurl"] = "https://www.site.com/page/"; parameters["data"] = "foo"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } diff --git a/TwoCaptcha.Tests/KeyCaptchaTest.cs b/TwoCaptcha.Tests/KeyCaptchaTest.cs index f16d2f7..921a03f 100644 --- a/TwoCaptcha.Tests/KeyCaptchaTest.cs +++ b/TwoCaptcha.Tests/KeyCaptchaTest.cs @@ -26,6 +26,7 @@ public async Task TestAllOptions() parameters["s_s_c_web_server_sign2"] = "2ca3abe86d90c6142d5571db98af6714"; parameters["pageurl"] = "https://www.keycaptcha.ru/demo-magnetic/"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } diff --git a/TwoCaptcha.Tests/LeminTest.cs b/TwoCaptcha.Tests/LeminTest.cs index fbbcc83..8da1b63 100644 --- a/TwoCaptcha.Tests/LeminTest.cs +++ b/TwoCaptcha.Tests/LeminTest.cs @@ -22,6 +22,7 @@ public async Task TestAllOptions() parameters["api_server"] = "api.leminnow.com"; parameters["pageurl"] = "http://sat2.aksigorta.com.tr"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } diff --git a/TwoCaptcha.Tests/MTCaptchaTest.cs b/TwoCaptcha.Tests/MTCaptchaTest.cs index 8d68f6e..d44b41a 100644 --- a/TwoCaptcha.Tests/MTCaptchaTest.cs +++ b/TwoCaptcha.Tests/MTCaptchaTest.cs @@ -20,6 +20,7 @@ public async Task TestAllOptions() parameters["sitekey"] = "MTPublic-KzqLY1cKH"; parameters["pageurl"] = "https://2captcha.com/demo/mtcaptcha"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(mtCaptcha, parameters); } diff --git a/TwoCaptcha.Tests/NormalTest.cs b/TwoCaptcha.Tests/NormalTest.cs index 18fc771..2eb6ca9 100644 --- a/TwoCaptcha.Tests/NormalTest.cs +++ b/TwoCaptcha.Tests/NormalTest.cs @@ -24,6 +24,7 @@ public async Task TestSingleFile() var parameters = new Dictionary(); parameters["method"] = "post"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; var files = new Dictionary(); files["file"] = image; @@ -42,6 +43,7 @@ public async Task TestSingleFileParameter() var parameters = new Dictionary(); parameters["method"] = "post"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; var files = new Dictionary(); files["file"] = image; @@ -59,6 +61,7 @@ public async Task TestBase64() parameters["method"] = "base64"; parameters["body"] = "..."; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } @@ -92,6 +95,7 @@ public async Task TestAllParameters() parameters["lang"] = "en"; parameters["textinstructions"] = hintText; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; var files = new Dictionary(); files["file"] = image; diff --git a/TwoCaptcha.Tests/ReCaptchaTest.cs b/TwoCaptcha.Tests/ReCaptchaTest.cs index 9f2eb23..1c18baa 100644 --- a/TwoCaptcha.Tests/ReCaptchaTest.cs +++ b/TwoCaptcha.Tests/ReCaptchaTest.cs @@ -29,6 +29,7 @@ public async Task TestV2() parameters["domain"] = "recaptcha.net"; parameters["data-s"] = "foo"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } @@ -53,6 +54,7 @@ public async Task TestV3() parameters["min_score"] = "0.3"; parameters["domain"] = "recaptcha.net"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } diff --git a/TwoCaptcha.Tests/RotateTest.cs b/TwoCaptcha.Tests/RotateTest.cs index 9f21272..9c6fcea 100644 --- a/TwoCaptcha.Tests/RotateTest.cs +++ b/TwoCaptcha.Tests/RotateTest.cs @@ -32,7 +32,7 @@ public async Task TestAllParameters() parameters["textinstructions"] = "Put the images in the correct way up"; parameters["body"] = base64EncodedImage; parameters["soft_id"] = "4582"; - + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } diff --git a/TwoCaptcha.Tests/TencentTest.cs b/TwoCaptcha.Tests/TencentTest.cs index bd13087..9c31b11 100644 --- a/TwoCaptcha.Tests/TencentTest.cs +++ b/TwoCaptcha.Tests/TencentTest.cs @@ -20,6 +20,7 @@ public async Task TestAllOptions() parameters["app_id"] = "190014885"; parameters["pageurl"] = "https://www.example.com/"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(tencent, parameters); } diff --git a/TwoCaptcha.Tests/TextTest.cs b/TwoCaptcha.Tests/TextTest.cs index 7a29d8a..e682710 100644 --- a/TwoCaptcha.Tests/TextTest.cs +++ b/TwoCaptcha.Tests/TextTest.cs @@ -19,6 +19,7 @@ public async Task TestSimpleText() parameters["method"] = "post"; parameters["textcaptcha"] = question; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } @@ -33,6 +34,7 @@ public async Task TestTextParameter() parameters["method"] = "post"; parameters["textcaptcha"] = question; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } @@ -49,6 +51,7 @@ public async Task TestAllParameters() parameters["textcaptcha"] = question; parameters["lang"] = "en"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } diff --git a/TwoCaptcha.Tests/TurnstileTest.cs b/TwoCaptcha.Tests/TurnstileTest.cs index 9e3918c..13e4aab 100644 --- a/TwoCaptcha.Tests/TurnstileTest.cs +++ b/TwoCaptcha.Tests/TurnstileTest.cs @@ -26,6 +26,7 @@ public async Task TestAllOptions() parameters["pagedata"] = "bar"; parameters["action"] = "baz"; parameters["soft_id"] = "4582"; + parameters["json"] = "0"; await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); } From 56efe49a25abf0e81f0375bd31bac5ab88b7e9ae Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Wed, 20 Nov 2024 07:20:40 +0300 Subject: [PATCH 8/9] temp --- TwoCaptcha/TwoCaptcha.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/TwoCaptcha/TwoCaptcha.cs b/TwoCaptcha/TwoCaptcha.cs index c67cae5..b7f1a2d 100644 --- a/TwoCaptcha/TwoCaptcha.cs +++ b/TwoCaptcha/TwoCaptcha.cs @@ -221,16 +221,25 @@ private string handleResponse(string response) { try { - dynamic jsonObject = JObject.Parse(response); + //test---------- + /* + string responseBody = await response.Content.ReadAsStringAsync(); + JObject jObject = JObject.Parse(responseBody); + JArray jArray = JArray.Parse(responseBody); + */ + //--------------- - string requestVal = jsonObject.request; + JObject jsonObject = JObject.Parse(response); + + string requestVal = jsonObject["request"].ToString(); if (requestVal.Equals("CAPCHA_NOT_READY")) { return null; } - - return JsonConvert.ToString(jsonObject); + //Todo: ERROR_CAPTCHA_UNSOLVABLE + //return JsonConvert.ToString(jsonObject); + return response; } catch (JsonException) From 1dccee84c34f9c54497822a7170a57b29f48601e Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Wed, 27 Nov 2024 10:57:57 +0300 Subject: [PATCH 9/9] cleanup --- TwoCaptcha.Examples/TextExample.cs | 2 +- TwoCaptcha/TwoCaptcha.cs | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/TwoCaptcha.Examples/TextExample.cs b/TwoCaptcha.Examples/TextExample.cs index eb27868..8112dae 100644 --- a/TwoCaptcha.Examples/TextExample.cs +++ b/TwoCaptcha.Examples/TextExample.cs @@ -8,7 +8,7 @@ public class TextExample { public TextExample(string apiKey) { - TwoCaptcha solver = new TwoCaptcha(apiKey, 1); + TwoCaptcha solver = new TwoCaptcha(apiKey); Text captcha = new Text("If tomorrow is Saturday, what day is today?"); diff --git a/TwoCaptcha/TwoCaptcha.cs b/TwoCaptcha/TwoCaptcha.cs index b7f1a2d..66115f1 100644 --- a/TwoCaptcha/TwoCaptcha.cs +++ b/TwoCaptcha/TwoCaptcha.cs @@ -221,30 +221,18 @@ private string handleResponse(string response) { try { - //test---------- - /* - string responseBody = await response.Content.ReadAsStringAsync(); - JObject jObject = JObject.Parse(responseBody); - JArray jArray = JArray.Parse(responseBody); - */ - //--------------- - - JObject jsonObject = JObject.Parse(response); + dynamic jsonObject = JObject.Parse(response); - string requestVal = jsonObject["request"].ToString(); + string requestVal = jsonObject.request; if (requestVal.Equals("CAPCHA_NOT_READY")) { return null; } - //Todo: ERROR_CAPTCHA_UNSOLVABLE - //return JsonConvert.ToString(jsonObject); return response; - } catch (JsonException) { - if (response.Equals("CAPCHA_NOT_READY")) { return null;