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..93f706f 100644
--- a/TwoCaptcha.Tests/AbstractWrapperTestCase.cs
+++ b/TwoCaptcha.Tests/AbstractWrapperTestCase.cs
@@ -26,15 +26,16 @@ Dictionary files
string apiKey = "API_KEY";
string captchaId = "123";
string code = "2763";
+ string json = "0";
parameters["key"] = apiKey;
var resParameters = new Dictionary();
resParameters["action"] = "get";
resParameters["id"] = captchaId;
+ resParameters["json"] = json;
resParameters["key"] = apiKey;
-
var apiClientMock = new Mock();
apiClientMock
.Setup(ac => ac.In(It.IsAny>(), It.IsAny>()))
@@ -48,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))
@@ -56,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);
}
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);
}
diff --git a/TwoCaptcha/TwoCaptcha.cs b/TwoCaptcha/TwoCaptcha.cs
index dca5786..66115f1 100644
--- a/TwoCaptcha/TwoCaptcha.cs
+++ b/TwoCaptcha/TwoCaptcha.cs
@@ -1,8 +1,9 @@
-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;
@@ -50,6 +51,11 @@ public class TwoCaptcha
*/
private bool lastCaptchaHasCallback;
+ /**
+ * JSON format response
+ */
+ public int ExtendedResponse { get; set; } = 0;
+
/**
* Network client
*/
@@ -73,6 +79,12 @@ public TwoCaptcha(string apiKey) : this()
ApiKey = apiKey;
}
+ public TwoCaptcha(string apiKey, int extendedResponse) : this()
+ {
+ ApiKey = apiKey;
+ ExtendedResponse = extendedResponse;
+ }
+
/**
* @param apiClient
*/
@@ -170,6 +182,73 @@ private long CurrentTime()
return Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds);
}
+ private string getCaptchaId(string response)
+ {
+ try
+ {
+ dynamic jsonObject = JObject.Parse(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);
+ }
+ }
+
+ private string handleResponse(string response)
+ {
+ try
+ {
+ dynamic jsonObject = JObject.Parse(response);
+
+ string requestVal = jsonObject.request;
+
+ if (requestVal.Equals("CAPCHA_NOT_READY"))
+ {
+ return null;
+ }
+ return response;
+ }
+ 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`
*
@@ -188,12 +267,7 @@ public async Task Send(Captcha.Captcha captcha)
string response = await apiClient.In(parameters, files);
- if (!response.StartsWith("OK|"))
- {
- throw new ApiException("Cannot recognise api response (" + response + ")");
- }
-
- return response.Substring(3);
+ return getCaptchaId(response);
}
/**
@@ -208,22 +282,13 @@ 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);
+ string responseStr = await Res(parameters);
- if (response.Equals("CAPCHA_NOT_READY"))
- {
- return null;
- }
-
- if (!response.StartsWith("OK|"))
- {
- throw new ApiException("Cannot recognise api response (" + response + ")");
- }
-
- return response.Substring(3);
+ return handleResponse(responseStr);
}
-
+
/**
* Gets account's balance
*
@@ -295,6 +360,7 @@ private async Task Res(Dictionary parameters)
private void SendAttachDefaultParameters(Dictionary parameters)
{
parameters["key"] = ApiKey;
+ parameters["json"] = ExtendedResponse.ToString();
if (Callback != null)
{
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