diff --git a/CapSolver/CapSolver.csproj b/CapSolver/CapSolver.csproj
index 453b6f5..3ad80a2 100644
--- a/CapSolver/CapSolver.csproj
+++ b/CapSolver/CapSolver.csproj
@@ -4,7 +4,7 @@
enable
enable
CapSolver
- 1.0.0-alpha
+ 1.2.1
Alperen Sert
Alperen Sert
CapSolver,ReCaptcha v2 solver, Bypass captcha, anti-captcha,
@@ -17,6 +17,6 @@
-
+
\ No newline at end of file
diff --git a/CapSolver/CapSolverClient.cs b/CapSolver/CapSolverClient.cs
index 3908f8d..efed143 100644
--- a/CapSolver/CapSolverClient.cs
+++ b/CapSolver/CapSolverClient.cs
@@ -9,60 +9,55 @@ namespace CapSolver;
public class CapSolverClient
{
- private readonly static string Balance = "/getBalance";
- private readonly static string CreateTask_ = "/createTask";
- private readonly static string GetTaskResult_ = "/getTaskResult";
- private readonly static string CreateTaskKasada = "/kasada/invoke";
- private readonly static string CreateTaskAntiAkamai = "/akamaibmp/invoke";
- private HttpClient _httpClient;
- private readonly static Uri _hostUrl = new Uri("https://api.capsolver.com");
- private readonly static Uri _betaHostUrl = new Uri("https://api-beta.capsolver.com");
+ private readonly HttpClient _httpClient;
+ private static readonly Uri HostUrl = new Uri("https://api.capsolver.com");
+ private static readonly Uri BetaHostUrl = new Uri("https://api-beta.capsolver.com");
private readonly string _clientKey;
- private Proxy? _proxy = null;
+ private Proxy? _proxy;
public CapSolverClient(string clientKey, bool beta = false)
{
_clientKey = clientKey;
- _httpClient = new HttpClient { BaseAddress = beta ? _betaHostUrl : _hostUrl };
+ _httpClient = new HttpClient { BaseAddress = beta ? BetaHostUrl : HostUrl };
}
public async Task GetBalance()
{
- VanillaTask data = new VanillaTask(_clientKey);
- HttpResponseMessage response = await MakeRequest(Balance, JsonConvert.SerializeObject(data));
- var r = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
- r = await CheckResponse(response);
- return r!.Balance;
+ var data = new VanillaTask(_clientKey);
+ var response = await MakeRequest(Endpoints.Balance, JsonConvert.SerializeObject(data));
+ var r = await CheckResponse(response);
+ return r.Balance;
}
public async Task> GetPackages()
{
- VanillaTask data = new VanillaTask(_clientKey);
- HttpResponseMessage response = await MakeRequest(Balance, JsonConvert.SerializeObject(data));
- var r = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
- r = await CheckResponse(response);
- return r!.Packages;
+ var data = new VanillaTask(_clientKey);
+ var response = await MakeRequest(Endpoints.Balance, JsonConvert.SerializeObject(data));
+ var r = await CheckResponse(response);
+ return r.Packages;
}
public async Task> GetTaskResult(string taskId) where T : ITaskResponse
{
- VanillaTask vt = new VanillaTask(_clientKey);
- vt.TaskId = taskId;
- HttpResponseMessage response = await MakeRequest(GetTaskResult_, JsonConvert.SerializeObject(vt));
- var r = JsonConvert.DeserializeObject>(await response.Content.ReadAsStringAsync());
- r = await CheckResponse>(response);
+ var vt = new VanillaTask(_clientKey)
+ {
+ TaskId = taskId
+ };
+ var response = await MakeRequest(Endpoints.GetTaskResult, JsonConvert.SerializeObject(vt));
+ var r = await CheckResponse>(response);
return r;
}
public async Task JoinTaskResult(string taskId, int maximumTime = 120) where T : ITaskResponse
{
- VanillaTask vt = new VanillaTask(_clientKey);
- vt.TaskId = taskId;
- for (int i = 0; i < maximumTime; i++)
+ var vt = new VanillaTask(_clientKey)
+ {
+ TaskId = taskId
+ };
+ for (var i = 0; i < maximumTime; i++)
{
- HttpResponseMessage response = await MakeRequest(GetTaskResult_, JsonConvert.SerializeObject(vt));
- var r = JsonConvert.DeserializeObject>(await response.Content.ReadAsStringAsync());
- r = await CheckResponse>(response);
+ var response = await MakeRequest(Endpoints.GetTaskResult, JsonConvert.SerializeObject(vt));
+ var r = await CheckResponse>(response);
if (IsReady(r) && r.Solution != null)
{
return r.Solution;
@@ -74,42 +69,47 @@ public async Task JoinTaskResult(string taskId, int maximumTime = 120) whe
public async Task CreateTask(ITask task)
{
- VanillaTask t = new VanillaTask(_clientKey);
+ var t = new VanillaTask(_clientKey);
t.UseAppId();
string data;
- if (task is IProxyTask && IsProxyActive())
- {
- JObject vt = JObject.FromObject(t);
- JObject t_ = JObject.FromObject(task);
- JObject p = JObject.FromObject(_proxy!);
- p.Merge(t_);
- vt["task"] = p;
- data = vt.ToString();
- }
- else if (task is IProxyTask && !IsProxyActive())
- {
- JObject vt = JObject.FromObject(t);
- JObject t_ = JObject.FromObject(task);
- t_["type"] += "ProxyLess";
- vt["task"] = t_;
- data = vt.ToString();
- }
- else
- {
- JObject vt = JObject.FromObject(t);
- JObject t_ = JObject.FromObject(task);
- vt["task"] = t_;
- data = vt.ToString();
- }
- string method = CreateTask_;
- if (task is AntiAkamaiBMPTask)
+ switch (task)
{
- method = CreateTaskAntiAkamai;
+ case IProxyTask when IsProxyActive():
+ {
+ var vt = JObject.FromObject(t);
+ var to = JObject.FromObject(task);
+ var p = JObject.FromObject(_proxy!);
+ p.Merge(to);
+ vt["task"] = p;
+ data = vt.ToString();
+ break;
+ }
+ case IProxyTask when !IsProxyActive():
+ {
+ var vt = JObject.FromObject(t);
+ var to = JObject.FromObject(task);
+ to["type"] += "ProxyLess";
+ vt["task"] = to;
+ data = vt.ToString();
+ break;
+ }
+ default:
+ {
+ var vt = JObject.FromObject(t);
+ var to = JObject.FromObject(task);
+ vt["task"] = to;
+ data = vt.ToString();
+ break;
+ }
}
- else if (task is AntiKasadaTask)
+ var method = task switch
{
- method = CreateTaskKasada;
- }
+ AntiAkamaiBMPTask => Endpoints.CreateTaskAntiAkamai,
+ AntiKasadaTask => Endpoints.CreateTaskKasada,
+ _ => Endpoints.CreateTask
+ };
+ if (task is HCaptchaTurboTask && IsProxyActive() == false)
+ throw new CapSolverException(13, "PROXY_NEEDED", "HCaptchaTurboTask requires your own proxies.");
var r = await CheckResponse(await MakeRequest(method, data));
return r.TaskId;
}
diff --git a/CapSolver/Tasks/HCaptchaTask.cs b/CapSolver/Tasks/HCaptchaTask.cs
index 2e2fbe8..95596e5 100644
--- a/CapSolver/Tasks/HCaptchaTask.cs
+++ b/CapSolver/Tasks/HCaptchaTask.cs
@@ -9,7 +9,7 @@ namespace CapSolver.Tasks;
public class HCaptchaTask : ITask, IProxyTask, IUserAgentTask
{
[JsonProperty("type")]
- private readonly string Type = "HCaptchaTask";
+ protected string Type = "HCaptchaTask";
///
/// Address of a webpage with hCaptcha
diff --git a/CapSolver/Tasks/HCaptchaTurboTask.cs b/CapSolver/Tasks/HCaptchaTurboTask.cs
new file mode 100644
index 0000000..e1b1bba
--- /dev/null
+++ b/CapSolver/Tasks/HCaptchaTurboTask.cs
@@ -0,0 +1,12 @@
+namespace CapSolver.Tasks;
+
+public class HCaptchaTurboTask : HCaptchaTask
+{
+ public HCaptchaTurboTask(string websiteUrl, string websiteKey,
+ object? enterprisePayload = null, bool? isEnterprise = null,
+ bool? isInvisible = null, string? userAgent = null)
+ : base(websiteUrl, websiteKey, enterprisePayload, isEnterprise, isInvisible, userAgent)
+ {
+ Type = "HCaptchaTurboTask";
+ }
+}
\ No newline at end of file
diff --git a/CapSolver/Utilities/Endpoints.cs b/CapSolver/Utilities/Endpoints.cs
new file mode 100644
index 0000000..91fc165
--- /dev/null
+++ b/CapSolver/Utilities/Endpoints.cs
@@ -0,0 +1,10 @@
+namespace CapSolver.Utilities;
+
+internal static class Endpoints
+{
+ public const string Balance = "/getBalance";
+ public const string CreateTask = "/createTask";
+ public const string GetTaskResult = "/getTaskResult";
+ public const string CreateTaskKasada = "/kasada/invoke";
+ public const string CreateTaskAntiAkamai = "/akamaibmp/invoke";
+}
\ No newline at end of file
diff --git a/README.md b/README.md
index 2f145a4..ab71cda 100644
--- a/README.md
+++ b/README.md
@@ -6,18 +6,18 @@
### Installation
via Package Manager:
```
-NuGet\Install-Package CapSolver -Version 1.0.0
+NuGet\Install-Package CapSolver -Version 1.2.1
```
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
via .NET CLI:
```ssh
-dotnet add package CapSolver --version 1.0.0
+dotnet add package CapSolver --version 1.2.1
```
via adding PackageReference:
```xml
-
+
```
For projects that support PackageReference, copy this XML node into the project file to reference the package.