Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON response format #36

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -240,7 +242,8 @@ captcha.SetUrl("https://mysite.com/captcha.html");

<sup>[API method description.](https://2captcha.com/2captcha-api#solving_hcaptcha)</sup>

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();
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Examples/HCaptchaExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion TwoCaptcha.Examples/TextExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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?");

Expand Down
6 changes: 4 additions & 2 deletions TwoCaptcha.Tests/AbstractWrapperTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ Dictionary<string, FileInfo> files
string apiKey = "API_KEY";
string captchaId = "123";
string code = "2763";
string json = "0";

parameters["key"] = apiKey;

var resParameters = new Dictionary<string, string>();
resParameters["action"] = "get";
resParameters["id"] = captchaId;
resParameters["json"] = json;
resParameters["key"] = apiKey;


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

await solver.Solve(captcha);

apiClientMock.Verify(ac => ac.In(
It.Is<Dictionary<string, string>>(actual => ParametersAreSame(parameters, actual)),
It.Is<Dictionary<string, FileInfo>>(actual => FilesAreSame(files, actual))
));

Assert.AreEqual(captchaId, captcha.Id);
Assert.AreEqual(code, captcha.Code);

}

private bool ParametersAreSame(Dictionary<string, string> expected, Dictionary<string, string> actual)
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/AmazonWafTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/AtbCAPTCHATest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/AudioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions TwoCaptcha.Tests/CanvasTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, FileInfo>();
files["file"] = image;
Expand All @@ -52,6 +53,7 @@ public async Task TestBase64()
parameters["body"] = "...";
parameters["textinstructions"] = hintText;
parameters["soft_id"] = "4582";
parameters["json"] = "0";

await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);
}
Expand Down Expand Up @@ -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<string, FileInfo>();
files["file"] = image;
Expand Down
2 changes: 1 addition & 1 deletion TwoCaptcha.Tests/CapyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions TwoCaptcha.Tests/CoordinatesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, FileInfo>();
files["file"] = image;
Expand All @@ -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<string, FileInfo>();
files["file"] = image;
Expand All @@ -62,6 +64,7 @@ public async Task TestBase64()
parameters["coordinatescaptcha"] = "1";
parameters["body"] = "...";
parameters["soft_id"] = "4582";
parameters["json"] = "0";

await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);
}
Expand All @@ -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<string, FileInfo>();
files["file"] = image;
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/CutcaptchaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/CyberSiARATest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/DataDomeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/FriendlyCaptchaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/FunCaptchaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/GeeTestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/GeeTestV4Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions TwoCaptcha.Tests/GridTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, FileInfo>();
files["file"] = image;
Expand All @@ -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<string, FileInfo>();
files["file"] = image;
Expand All @@ -61,6 +63,7 @@ public async Task TestBase64()
parameters["body"] = "...";
parameters["recaptcha"] = "1";
parameters["soft_id"] = "4582";
parameters["json"] = "0";

await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);
}
Expand Down Expand Up @@ -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<string, FileInfo>();
files["file"] = image;
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/HCaptchaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/KeyCaptchaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/LeminTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/MTCaptchaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions TwoCaptcha.Tests/NormalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public async Task TestSingleFile()
var parameters = new Dictionary<string, string>();
parameters["method"] = "post";
parameters["soft_id"] = "4582";
parameters["json"] = "0";

var files = new Dictionary<string, FileInfo>();
files["file"] = image;
Expand All @@ -42,6 +43,7 @@ public async Task TestSingleFileParameter()
var parameters = new Dictionary<string, string>();
parameters["method"] = "post";
parameters["soft_id"] = "4582";
parameters["json"] = "0";

var files = new Dictionary<string, FileInfo>();
files["file"] = image;
Expand All @@ -59,6 +61,7 @@ public async Task TestBase64()
parameters["method"] = "base64";
parameters["body"] = "...";
parameters["soft_id"] = "4582";
parameters["json"] = "0";

await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);
}
Expand Down Expand Up @@ -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<string, FileInfo>();
files["file"] = image;
Expand Down
2 changes: 2 additions & 0 deletions TwoCaptcha.Tests/ReCaptchaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion TwoCaptcha.Tests/RotateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/TencentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions TwoCaptcha.Tests/TextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/TurnstileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions TwoCaptcha.Tests/YandexTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading