Skip to content
Merged
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
98 changes: 53 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
# C# Module for 2Captcha API
The easiest way to quickly integrate [2Captcha] into your code to automate solving of any types of captcha.

- [Installation](#installation)
- [Configuration](#configuration)
- [Solve captcha](#solve-captcha)
- [Normal Captcha](#normal-captcha)
- [Text](#text-captcha)
- [ReCaptcha v2](#recaptcha-v2)
- [ReCaptcha v3](#recaptcha-v3)
- [FunCaptcha](#funcaptcha)
- [GeeTest](#geetest)
- [GeeTestV4](#geetestv4)
- [hCaptcha](#hcaptcha)
- [KeyCaptcha](#keycaptcha)
- [Capy](#capy)
- [Grid (ReCaptcha V2 Old Method)](#grid)
- [Canvas](#canvas)
- [ClickCaptcha](#clickcaptcha)
- [Rotate](#rotate)
- [Audio](#audio)
- [Yandex](#yandex)
- [Lemin](#lemin)
- [Turnstile](#turnstile)
- [AmazonWaf](#amazonwaf)
- [Other methods](#other-methods)
- [send / getResult](#send--getresult)
- [balance](#balance)
- [report](#report)
- [Error handling](#error-handling)
- [C# Module for 2Captcha API](#c-module-for-2captcha-api)
- [Installation](#installation)
- [Configuration](#configuration)
- [TwoCaptcha instance options](#twocaptcha-instance-options)
- [Solve captcha](#solve-captcha)
- [Captcha options](#captcha-options)
- [Basic example](#basic-example)
- [Normal Captcha](#normal-captcha)
- [Text Captcha](#text-captcha)
- [ReCaptcha v2](#recaptcha-v2)
- [ReCaptcha v3](#recaptcha-v3)
- [FunCaptcha](#funcaptcha)
- [GeeTest](#geetest)
- [GeeTestV4](#geetestv4)
- [hCaptcha](#hcaptcha)
- [KeyCaptcha](#keycaptcha)
- [Capy](#capy)
- [Grid](#grid)
- [Canvas](#canvas)
- [ClickCaptcha](#clickcaptcha)
- [Rotate](#rotate)
- [Audio](#audio)
- [Yandex](#yandex)
- [Lemin](#lemin)
- [Turnstile](#turnstile)
- [AmazonWaf](#amazonwaf)
- [Other methods](#other-methods)
- [send / getResult](#send--getresult)
- [balance](#balance)
- [report](#report)
- [Error handling](#error-handling)

## Installation
Install nuget package from [nuget]
Expand All @@ -48,13 +52,13 @@ solver.PollingInterval = 10;

### TwoCaptcha instance options

|Option|Default value|Description|
|---|---|---|
|softId|-|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|
| Option | Default value | Description |
| ---------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| softId | - | 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 |

> **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 All @@ -63,17 +67,17 @@ To get the answer manually use [getResult method](#send--getresult)
When you submit any image-based captcha use can provide additional options to help 2captcha workers to solve it properly.

### Captcha options
|Option|Default Value|Description|
|---|---|---|
|numeric|0|Defines if captcha contains numeric or other symbols [see more info in the API docs][post options]|
|minLength|0|minimal answer lenght|
|maxLength|0|maximum answer length|
|phrase|0|defines if the answer contains multiple words or not|
|caseSensitive|0|defines if the answer is case sensitive|
|calc|0|defines captcha requires calculation|
|lang|-|defines the captcha language, see the [list of supported languages] |
|hintImg|-|an image with hint shown to workers with the captcha|
|hintText|-|hint or task text shown to workers with the captcha|
| Option | Default Value | Description |
| ------------- | ------------- | -------------------------------------------------------------------------------------------------- |
| numeric | 0 | Defines if captcha contains numeric or other symbols [see more info in the API docs][post options] |
| minLength | 0 | minimal answer lenght |
| maxLength | 0 | maximum answer length |
| phrase | 0 | defines if the answer contains multiple words or not |
| caseSensitive | 0 | defines if the answer is case sensitive |
| calc | 0 | defines captcha requires calculation |
| lang | - | defines the captcha language, see the [list of supported languages] |
| hintImg | - | an image with hint shown to workers with the captcha |
| hintText | - | hint or task text shown to workers with the captcha |

Below you can find basic examples for every captcha type. Check out [examples directory] to find more examples with all available options.

Expand Down Expand Up @@ -194,6 +198,7 @@ Use this method to solve hCaptcha challenge. Returns a token to bypass captcha.
HCaptcha captcha = new HCaptcha();
captcha.SetSiteKey("10000000-ffff-ffff-ffff-000000000001");
captcha.SetUrl("https://www.site.com/page/");
captcha.SetData("foo");
captcha.SetProxy("HTTPS", "login:password@IP_address:PORT");
```

Expand Down Expand Up @@ -307,6 +312,9 @@ Use this method to solve Turnstile and obtain a token to bypass the protection.
Turnstile captcha = new Turnstile();
captcha.SetSiteKey("0x4AAAAAAAChNiVJM_WtShFf");
captcha.SetUrl("https://ace.fusionist.io");
captcha.SetData("foo");
captcha.SetPageData("bar");
captcha.SetAction("baz");
```

### AmazonWaf
Expand Down
2 changes: 2 additions & 0 deletions TwoCaptcha.Tests/HCaptchaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ public async Task TestAllOptions()
HCaptcha captcha = new HCaptcha();
captcha.SetSiteKey("f1ab2cdefa3456789012345b6c78d90e");
captcha.SetUrl("https://www.site.com/page/");
captcha.SetData("foo");

var parameters = new Dictionary<string, string>();
parameters["method"] = "hcaptcha";
parameters["sitekey"] = "f1ab2cdefa3456789012345b6c78d90e";
parameters["pageurl"] = "https://www.site.com/page/";
parameters["data"] = "foo";

await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);
}
Expand Down
2 changes: 2 additions & 0 deletions TwoCaptcha.Tests/ReCaptchaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public async Task TestV2()
captcha.SetInvisible(true);
captcha.SetAction("verify");
captcha.SetDomain("recaptcha.net");
captcha.SetDataS("foo");

var parameters = new Dictionary<string, string>();
parameters["method"] = "userrecaptcha";
Expand All @@ -26,6 +27,7 @@ public async Task TestV2()
parameters["invisible"] = "1";
parameters["action"] = "verify";
parameters["domain"] = "recaptcha.net";
parameters["data-s"] = "foo";

await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);
}
Expand Down
6 changes: 6 additions & 0 deletions TwoCaptcha.Tests/TurnstileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ public async Task TestAllOptions()
Turnstile captcha = new Turnstile();
captcha.SetSiteKey("0x4AAAAAAAChNiVJM_WtShFf");
captcha.SetUrl("https://ace.fusionist.io");
captcha.SetData("foo");
captcha.SetPageData("bar");
captcha.SetAction("baz");

var parameters = new Dictionary<string, string>();
parameters["method"] = "turnstile";
parameters["sitekey"] = "0x4AAAAAAAChNiVJM_WtShFf";
parameters["pageurl"] = "https://ace.fusionist.io";
parameters["data"] = "foo";
parameters["pagedata"] = "bar";
parameters["action"] = "baz";

await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);
}
Expand Down
5 changes: 5 additions & 0 deletions TwoCaptcha/Captcha/HCaptcha.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ public void SetUrl(string url)
{
parameters["pageurl"] = url;
}

public void SetData(string data)
{
parameters["data"] = data;
}
}
}
5 changes: 5 additions & 0 deletions TwoCaptcha/Captcha/ReCaptcha.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ public void SetEnterprise(bool invisible)
{
parameters["enterprise"] = invisible ? "1" : "0";
}

public void SetDataS(string data)
{
parameters["data-s"] = data;
}
}
}
13 changes: 13 additions & 0 deletions TwoCaptcha/Captcha/Turnstile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,18 @@ public void SetUrl(string url)
{
parameters["pageurl"] = url;
}

public void SetAction(string action)
{
parameters["action"] = action;
}
public void SetData(string data)
{
parameters["data"] = data;
}
public void SetPageData(string pagedata)
{
parameters["pagedata"] = pagedata;
}
}
}