Skip to content
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
27 changes: 7 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Examples of API requests for different captcha types are available on the [C# ca
- [FunCaptcha](#funcaptcha)
- [GeeTest](#geetest)
- [GeeTest v4](#geetest-v4)
- [hCaptcha](#hcaptcha)
- [KeyCaptcha](#keycaptcha)
- [Capy](#capy)
- [Grid](#grid)
Expand Down Expand Up @@ -72,17 +71,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 All @@ -94,7 +95,7 @@ When you submit any image-based captcha use can provide additional options to he
| 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 |
| minLength | 0 | minimal answer length |
| 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 |
Expand Down Expand Up @@ -236,20 +237,6 @@ captcha.SetChallenge("12345678abc90123d45678ef90123a456b");
captcha.SetUrl("https://mysite.com/captcha.html");
```

### hCaptcha

<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.

```csharp
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");
```

### KeyCaptcha

<sup>[API method description.](https://2captcha.com/2captcha-api#solving_keycaptcha)</sup>
Expand Down Expand Up @@ -537,7 +524,7 @@ await solver.Report(captcha.Id, false); // captcha solved incorrectly
```
## Proxies

You can pass your proxy as an additional argument for methods: recaptcha, funcaptcha, geetest, geetest v4, hcaptcha, keycaptcha, capy puzzle, lemin, cloudflare turnstile, amazon waf, friendly captcha, mtcaptcha, cutcaptcha, cybersiara, datadome, atbcaptcha, tencent and etc. The proxy will be forwarded to the API to solve the captcha.
You can pass your proxy as an additional argument for methods: recaptcha, funcaptcha, geetest, geetest v4, keycaptcha, capy puzzle, lemin, cloudflare turnstile, amazon waf, friendly captcha, mtcaptcha, cutcaptcha, cybersiara, datadome, atbcaptcha, tencent and etc. The proxy will be forwarded to the API to solve the captcha.

We have our own proxies that we can offer you. [Buy residential proxies] for avoid restrictions and blocks. [Quick start].

Expand Down Expand Up @@ -596,11 +583,11 @@ The graphics and trademarks included in this repository are not covered by the M
<!-- Shared links -->
[nuget]: https://www.nuget.org/packages/2captcha-csharp/
[2Captcha]: https://2captcha.com/
[2captcha sofware catalog]: https://2captcha.com/software
[2captcha software catalog]: https://2captcha.com/software
[Pingback settings]: https://2captcha.com/setting/pingback
[Post options]: https://2captcha.com/2captcha-api#normal_post
[list of supported languages]: https://2captcha.com/2captcha-api#language
[Examples directory]: /TwoCaptcha.Examples
[residential proxies]: https://2captcha.com/proxy/residential-proxies
[Buy residential proxies]: https://2captcha.com/proxy/residential-proxies
[Quick start]: https://2captcha.com/proxy?openAddTrafficModal=true
[Quick start]: https://2captcha.com/proxy?openAddTrafficModal=true
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
29 changes: 0 additions & 29 deletions TwoCaptcha.Examples/HCaptchaOptionsExample.cs

This file was deleted.

8 changes: 0 additions & 8 deletions TwoCaptcha.Examples/Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,6 @@ public static void Main(string[] args)
GridOptionsExample GridOptionsExample = new GridOptionsExample(apiKey);
break;

case "HCaptchaExample":
HCaptchaExample HCaptchaExample = new HCaptchaExample(apiKey);
break;

case "HCaptchaOptionsExample":
HCaptchaOptionsExample HCaptchaOptionsExample = new HCaptchaOptionsExample(apiKey);
break;

case "KeyCaptchaExample":
KeyCaptchaExample KeyCaptchaExample = new KeyCaptchaExample(apiKey);
break;
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
Loading