Skip to content

Commit d5c3cac

Browse files
author
victorkowalski
committed
merge json
2 parents 5abfdf6 + 1dccee8 commit d5c3cac

30 files changed

Lines changed: 166 additions & 27 deletions

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,19 @@ solver.Callback = "https://your.site/result-receiver";
7171
solver.DefaultTimeout = 120;
7272
solver.RecaptchaTimeout = 600;
7373
solver.PollingInterval = 10;
74+
solver.ExtendedResponse = 1;
7475
```
7576

7677
### TwoCaptcha instance options
7778

7879
| Option | Default value | Description |
7980
| ---------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
80-
| softId | 4582 | your software ID obtained after publishing in [2captcha software catalog] |
81+
| softId | 4582 | your software ID obtained after publishing in [2captcha sofware catalog] |
8182
| callback | - | URL of your web-sever that receives the captcha recognition result. The URl should be first registered in [pingback settings] of your account |
8283
| 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 |
8384
| recaptchaTimeout | 600 | Polling timeout for reCAPTCHA in seconds. Defines how long the module tries to get the answer from `res.php` API endpoint |
8485
| pollingInterval | 10 | Interval in seconds between requests to `res.php` API endpoint, setting values less than 5 seconds is not recommended |
86+
| json | 0 | Json or String format response from `res.php` API endpoint, extendedResponse = 1 returns JSON format response |
8587

8688
> **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.
8789
To get the answer manually use [getResult method](#send--getresult)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Linq;
3+
using TwoCaptcha.Captcha;
4+
5+
namespace TwoCaptcha.Examples
6+
{
7+
public class HCaptchaExample
8+
{
9+
public HCaptchaExample(string apiKey)
10+
{
11+
TwoCaptcha solver = new TwoCaptcha(apiKey);
12+
solver.ExtendedResponse = 1;
13+
14+
HCaptcha captcha = new HCaptcha();
15+
captcha.SetSiteKey("c0421d06-b92e-47fc-ab9a-5caa43c04538");
16+
captcha.SetUrl("https://2captcha.com/demo/hcaptcha");
17+
18+
try
19+
{
20+
solver.Solve(captcha).Wait();
21+
Console.WriteLine("Captcha solved: " + captcha.Code);
22+
}
23+
catch (AggregateException e)
24+
{
25+
Console.WriteLine("Error occurred: " + e.InnerExceptions.First().Message);
26+
}
27+
}
28+
}
29+
}

TwoCaptcha.Tests/AbstractWrapperTestCase.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ Dictionary<string, FileInfo> files
2626
string apiKey = "API_KEY";
2727
string captchaId = "123";
2828
string code = "2763";
29+
string json = "0";
2930

3031
parameters["key"] = apiKey;
3132

3233
var resParameters = new Dictionary<string, string>();
3334
resParameters["action"] = "get";
3435
resParameters["id"] = captchaId;
36+
resParameters["json"] = json;
3537
resParameters["key"] = apiKey;
3638

37-
3839
var apiClientMock = new Mock<ApiClient>();
3940
apiClientMock
4041
.Setup(ac => ac.In(It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, FileInfo>>()))
@@ -48,14 +49,15 @@ Dictionary<string, FileInfo> files
4849
solver.SetApiClient(apiClientMock.Object);
4950

5051
await solver.Solve(captcha);
51-
52+
5253
apiClientMock.Verify(ac => ac.In(
5354
It.Is<Dictionary<string, string>>(actual => ParametersAreSame(parameters, actual)),
5455
It.Is<Dictionary<string, FileInfo>>(actual => FilesAreSame(files, actual))
5556
));
5657

5758
Assert.AreEqual(captchaId, captcha.Id);
5859
Assert.AreEqual(code, captcha.Code);
60+
5961
}
6062

6163
private bool ParametersAreSame(Dictionary<string, string> expected, Dictionary<string, string> actual)

TwoCaptcha.Tests/AmazonWafTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public async Task TestAllOptions()
2424
parameters["context"] = "test_iv";
2525
parameters["iv"] = "test_context";
2626
parameters["soft_id"] = "4582";
27+
parameters["json"] = "0";
2728

2829
await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);
2930
}

TwoCaptcha.Tests/AtbCAPTCHATest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public async Task TestAllOptions()
2222
parameters["api_server"] = "https://cap.aisecurius.com";
2323
parameters["pageurl"] = "https://www.example.com/";
2424
parameters["soft_id"] = "4582";
25+
parameters["json"] = "0";
2526

2627
await CheckIfCorrectParamsSendAndResultReturned(atbCAPTCHA, parameters);
2728
}

TwoCaptcha.Tests/AudioTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public async Task TestAllParameters()
2828
parameters["lang"] = "en";
2929
parameters["body"] = base64EncodedImage;
3030
parameters["soft_id"] = "4582";
31+
parameters["json"] = "0";
3132

3233

3334
await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);

TwoCaptcha.Tests/CanvasTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public async Task TestSingleFile()
3131
parameters["canvas"] = "1";
3232
parameters["textinstructions"] = hintText;
3333
parameters["soft_id"] = "4582";
34+
parameters["json"] = "0";
3435

3536
var files = new Dictionary<string, FileInfo>();
3637
files["file"] = image;
@@ -52,6 +53,7 @@ public async Task TestBase64()
5253
parameters["body"] = "...";
5354
parameters["textinstructions"] = hintText;
5455
parameters["soft_id"] = "4582";
56+
parameters["json"] = "0";
5557

5658
await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);
5759
}
@@ -79,6 +81,7 @@ public async Task TestAllParameters()
7981
parameters["lang"] = "en";
8082
parameters["textinstructions"] = hintText;
8183
parameters["soft_id"] = "4582";
84+
parameters["json"] = "0";
8285

8386
var files = new Dictionary<string, FileInfo>();
8487
files["file"] = image;

TwoCaptcha.Tests/CapyTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public async Task TestAllOptions()
2222
parameters["pageurl"] = "http://mysite.com/";
2323
parameters["api_server"] = "https://myapiserver.com/";
2424
parameters["soft_id"] = "4582";
25-
25+
parameters["json"] = "0";
2626

2727
await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);
2828
}

TwoCaptcha.Tests/CoordinatesTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public async Task TestSingleFile()
2525
parameters["method"] = "post";
2626
parameters["coordinatescaptcha"] = "1";
2727
parameters["soft_id"] = "4582";
28+
parameters["json"] = "0";
2829

2930
var files = new Dictionary<string, FileInfo>();
3031
files["file"] = image;
@@ -44,6 +45,7 @@ public async Task TestSingleFileParameter()
4445
parameters["method"] = "post";
4546
parameters["coordinatescaptcha"] = "1";
4647
parameters["soft_id"] = "4582";
48+
parameters["json"] = "0";
4749

4850
var files = new Dictionary<string, FileInfo>();
4951
files["file"] = image;
@@ -62,6 +64,7 @@ public async Task TestBase64()
6264
parameters["coordinatescaptcha"] = "1";
6365
parameters["body"] = "...";
6466
parameters["soft_id"] = "4582";
67+
parameters["json"] = "0";
6568

6669
await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);
6770
}
@@ -84,6 +87,7 @@ public async Task TestAllParameters()
8487
parameters["lang"] = "en";
8588
parameters["textinstructions"] = hintText;
8689
parameters["soft_id"] = "4582";
90+
parameters["json"] = "0";
8791

8892
var files = new Dictionary<string, FileInfo>();
8993
files["file"] = image;

TwoCaptcha.Tests/CutcaptchaTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public async Task TestAllOptions()
2121
parameters["pageurl"] = "https://example.cc/foo/bar.html";
2222
parameters["api_key"] = "SAb83IIB";
2323
parameters["soft_id"] = "4582";
24+
parameters["json"] = "0";
2425

2526
await CheckIfCorrectParamsSendAndResultReturned(cutcaptcha, parameters);
2627
}

0 commit comments

Comments
 (0)