From 0dea0f2f4a388706ae3eb62b9fefd6d715960bb1 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 1 Nov 2026 21:46:02 +0200 Subject: [PATCH 1/3] Replace Newtonsoft.Json with System.Text.Json --- .../FlareSolverrSharp.Sample.csproj | 2 +- .../FlareSolverrSharp.csproj | 3 +- src/FlareSolverrSharp/Solvers/FlareSolverr.cs | 17 +-- .../Types/FlareSolverrRequest.cs | 18 +-- .../Types/FlareSolverrRequestGet.cs | 8 +- .../Types/FlareSolverrRequestPost.cs | 12 +- .../Types/FlareSolverrRequestProxy.cs | 14 +-- .../Types/FlareSolverrResponse.cs | 109 +++++++++++++----- .../Types/FlareSolverrStatusCode.cs | 3 +- .../FlareSolverrSharp.Tests.csproj | 8 +- 10 files changed, 122 insertions(+), 72 deletions(-) diff --git a/sample/FlareSolverrSharp.Sample/FlareSolverrSharp.Sample.csproj b/sample/FlareSolverrSharp.Sample/FlareSolverrSharp.Sample.csproj index 9da338b..be99d4c 100644 --- a/sample/FlareSolverrSharp.Sample/FlareSolverrSharp.Sample.csproj +++ b/sample/FlareSolverrSharp.Sample/FlareSolverrSharp.Sample.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net10.0 FlareSolverrSharp.Sample FlareSolverrSharp.Sample 3.0.7 diff --git a/src/FlareSolverrSharp/FlareSolverrSharp.csproj b/src/FlareSolverrSharp/FlareSolverrSharp.csproj index 5c89a37..7725ba3 100644 --- a/src/FlareSolverrSharp/FlareSolverrSharp.csproj +++ b/src/FlareSolverrSharp/FlareSolverrSharp.csproj @@ -15,6 +15,7 @@ - + + diff --git a/src/FlareSolverrSharp/Solvers/FlareSolverr.cs b/src/FlareSolverrSharp/Solvers/FlareSolverr.cs index 9109af6..db9b433 100644 --- a/src/FlareSolverrSharp/Solvers/FlareSolverr.cs +++ b/src/FlareSolverrSharp/Solvers/FlareSolverr.cs @@ -1,12 +1,14 @@ using System; using System.Net; using System.Net.Http; +using System.Net.Http.Json; using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading.Tasks; using FlareSolverrSharp.Exceptions; using FlareSolverrSharp.Types; using FlareSolverrSharp.Utilities; -using Newtonsoft.Json; namespace FlareSolverrSharp.Solvers { @@ -101,14 +103,13 @@ await Locker.LockAsync(async () => throw new FlareSolverrException("HTTP StatusCode not 200 or 500. Status is :" + response.StatusCode); } - var resContent = await response.Content.ReadAsStringAsync(); try { - result = JsonConvert.DeserializeObject(resContent); + result = await response.Content.ReadFromJsonAsync(); } catch (Exception) { - throw new FlareSolverrException("Error parsing response, check FlareSolverr. Response: " + resContent); + throw new FlareSolverrException("Error parsing response, check FlareSolverr. Response: " + await response.Content.ReadAsStringAsync()); } try @@ -170,12 +171,12 @@ private FlareSolverrRequestProxy GetProxy() private HttpContent GetSolverRequestContent(FlareSolverrRequest request) { - var payload = JsonConvert.SerializeObject(request, new JsonSerializerSettings + var payload = JsonSerializer.Serialize(request, new JsonSerializerOptions { - NullValueHandling = NullValueHandling.Ignore + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, }); - HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json"); - return content; + + return new StringContent(payload, Encoding.UTF8, "application/json"); } private HttpContent GenerateFlareSolverrRequest(HttpRequestMessage request, string sessionId = "") diff --git a/src/FlareSolverrSharp/Types/FlareSolverrRequest.cs b/src/FlareSolverrSharp/Types/FlareSolverrRequest.cs index 49bd18b..30acaa6 100644 --- a/src/FlareSolverrSharp/Types/FlareSolverrRequest.cs +++ b/src/FlareSolverrSharp/Types/FlareSolverrRequest.cs @@ -1,19 +1,19 @@ -using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace FlareSolverrSharp.Types { public class FlareSolverrRequest { - [JsonProperty("cmd")] - public string Cmd; + [JsonPropertyName("cmd")] + public string Cmd { get; set; } - [JsonProperty("url")] - public string Url; + [JsonPropertyName("url")] + public string Url { get; set; } - [JsonProperty("session")] - public string Session; + [JsonPropertyName("session")] + public string Session { get; set; } - [JsonProperty("proxy")] - public FlareSolverrRequestProxy Proxy; + [JsonPropertyName("proxy")] + public FlareSolverrRequestProxy Proxy { get; set; } } } diff --git a/src/FlareSolverrSharp/Types/FlareSolverrRequestGet.cs b/src/FlareSolverrSharp/Types/FlareSolverrRequestGet.cs index 41b520b..e707aad 100644 --- a/src/FlareSolverrSharp/Types/FlareSolverrRequestGet.cs +++ b/src/FlareSolverrSharp/Types/FlareSolverrRequestGet.cs @@ -1,10 +1,10 @@ -using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace FlareSolverrSharp.Types { public class FlareSolverrRequestGet : FlareSolverrRequest { - [JsonProperty("maxTimeout")] - public int MaxTimeout; + [JsonPropertyName("maxTimeout")] + public int MaxTimeout { get; set; } } -} \ No newline at end of file +} diff --git a/src/FlareSolverrSharp/Types/FlareSolverrRequestPost.cs b/src/FlareSolverrSharp/Types/FlareSolverrRequestPost.cs index 932c5f1..6ef7052 100644 --- a/src/FlareSolverrSharp/Types/FlareSolverrRequestPost.cs +++ b/src/FlareSolverrSharp/Types/FlareSolverrRequestPost.cs @@ -1,13 +1,13 @@ -using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace FlareSolverrSharp.Types { public class FlareSolverrRequestPost : FlareSolverrRequest { - [JsonProperty("postData")] - public string PostData; + [JsonPropertyName("postData")] + public string PostData { get; set; } - [JsonProperty("maxTimeout")] - public int MaxTimeout; + [JsonPropertyName("maxTimeout")] + public int MaxTimeout { get; set; } } -} \ No newline at end of file +} diff --git a/src/FlareSolverrSharp/Types/FlareSolverrRequestProxy.cs b/src/FlareSolverrSharp/Types/FlareSolverrRequestProxy.cs index 9186e09..a04bed4 100644 --- a/src/FlareSolverrSharp/Types/FlareSolverrRequestProxy.cs +++ b/src/FlareSolverrSharp/Types/FlareSolverrRequestProxy.cs @@ -1,16 +1,16 @@ -using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace FlareSolverrSharp.Types { public class FlareSolverrRequestProxy { - [JsonProperty("url")] - public string Url; + [JsonPropertyName("url")] + public string Url { get; set; } - [JsonProperty("username")] - public string Username; + [JsonPropertyName("username")] + public string Username { get; set; } - [JsonProperty("password")] - public string Password; + [JsonPropertyName("password")] + public string Password { get; set; } } } diff --git a/src/FlareSolverrSharp/Types/FlareSolverrResponse.cs b/src/FlareSolverrSharp/Types/FlareSolverrResponse.cs index e852ef7..5124159 100644 --- a/src/FlareSolverrSharp/Types/FlareSolverrResponse.cs +++ b/src/FlareSolverrSharp/Types/FlareSolverrResponse.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using System.Text.Json.Serialization; // ReSharper disable UnusedMember.Global // ReSharper disable UnassignedField.Global @@ -7,38 +7,83 @@ namespace FlareSolverrSharp.Types { public class FlareSolverrResponse { - public string Status; - public string Message; - public long StartTimestamp; - public long EndTimestamp; - public string Version; - public Solution Solution; - public string Session; - public string[] Sessions; + [JsonPropertyName("status")] + public string Status { get; set; } + + [JsonPropertyName("message")] + public string Message { get; set; } + + [JsonPropertyName("startTimestamp")] + public long StartTimestamp { get; set; } + + [JsonPropertyName("endTimestamp")] + public long EndTimestamp { get; set; } + + [JsonPropertyName("version")] + public string Version { get; set; } + + [JsonPropertyName("solution")] + public Solution Solution { get; set; } + + [JsonPropertyName("session")] + public string Session { get; set; } + + [JsonPropertyName("sessions")] + public string[] Sessions { get; set; } } public class Solution { - public string Url; - public string Status; - public Headers Headers; - public string Response; - public Cookie[] Cookies; - public string UserAgent; + [JsonPropertyName("url")] + public string Url { get; set; } + + [JsonPropertyName("status")] + public string Status { get; set; } + + [JsonPropertyName("headers")] + public Headers Headers { get; set; } + + [JsonPropertyName("response")] + public string Response { get; set; } + + [JsonPropertyName("cookies")] + public Cookie[] Cookies { get; set; } + + [JsonPropertyName("userAgent")] + public string UserAgent { get; set; } } public class Cookie { - public string Name; - public string Value; - public string Domain; - public string Path; - public double Expires; - public int Size; - public bool HttpOnly; - public bool Secure; - public bool Session; - public string SameSite; + [JsonPropertyName("name")] + public string Name { get; set; } + + [JsonPropertyName("value")] + public string Value { get; set; } + + [JsonPropertyName("domain")] + public string Domain { get; set; } + + [JsonPropertyName("path")] + public string Path { get; set; } + + [JsonPropertyName("expiry")] + public double Expires { get; set; } + + [JsonPropertyName("size")] + public int Size { get; set; } + + [JsonPropertyName("httpOnly")] + public bool HttpOnly { get; set; } + + [JsonPropertyName("secure")] + public bool Secure { get; set; } + + [JsonPropertyName("session")] + public bool Session { get; set; } + + [JsonPropertyName("sameSite")] + public string SameSite { get; set; } public string ToHeaderValue() => $"{Name}={Value}"; public System.Net.Cookie ToCookieObj() => new System.Net.Cookie(Name, Value); @@ -47,9 +92,13 @@ public class Cookie public class Headers { - public string Status; - public string Date; - [JsonProperty(PropertyName = "content-type")] - public string ContentType; + [JsonPropertyName("status")] + public string Status { get; set; } + + [JsonPropertyName("date")] + public string Date { get; set; } + + [JsonPropertyName("content-type")] + public string ContentType { get; set; } } -} \ No newline at end of file +} diff --git a/src/FlareSolverrSharp/Types/FlareSolverrStatusCode.cs b/src/FlareSolverrSharp/Types/FlareSolverrStatusCode.cs index 0330394..f05d28e 100644 --- a/src/FlareSolverrSharp/Types/FlareSolverrStatusCode.cs +++ b/src/FlareSolverrSharp/Types/FlareSolverrStatusCode.cs @@ -1,5 +1,4 @@ - -// ReSharper disable InconsistentNaming +// ReSharper disable InconsistentNaming namespace FlareSolverrSharp.Types { public enum FlareSolverrStatusCode diff --git a/test/FlareSolverrSharp.Tests/FlareSolverrSharp.Tests.csproj b/test/FlareSolverrSharp.Tests/FlareSolverrSharp.Tests.csproj index ebaeed1..afe6a27 100644 --- a/test/FlareSolverrSharp.Tests/FlareSolverrSharp.Tests.csproj +++ b/test/FlareSolverrSharp.Tests/FlareSolverrSharp.Tests.csproj @@ -1,7 +1,7 @@  - net7.0 + net10.0 false FlareSolverrSharp.Tests FlareSolverrSharp.Tests @@ -9,9 +9,9 @@ - - - + + + From 95650297a8c611e0f43f34a717f580aa93430ff0 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 1 Nov 2026 21:49:43 +0200 Subject: [PATCH 2/3] Use latest dotnet LTS --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7684bff..0290567 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,6 +22,9 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v6 + with: + dotnet-version: latest + dotnet-channel: lts - name: Build run: dotnet build src/FlareSolverrSharp --configuration Release From c8691988b4fffa9364f03f0dbce984d940bdea2d Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 1 Nov 2026 21:51:30 +0200 Subject: [PATCH 3/3] Bump version to 5.0.0 --- src/FlareSolverrSharp/FlareSolverrSharp.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FlareSolverrSharp/FlareSolverrSharp.csproj b/src/FlareSolverrSharp/FlareSolverrSharp.csproj index 7725ba3..bf1a889 100644 --- a/src/FlareSolverrSharp/FlareSolverrSharp.csproj +++ b/src/FlareSolverrSharp/FlareSolverrSharp.csproj @@ -3,7 +3,7 @@ netstandard2.0 FlareSolverrSharp FlareSolverrSharp - 4.0.0 + 5.0.0 Diego Heras (ngosang) FlareSolverr .Net / Proxy server to bypass Cloudflare protection. flaresolverr, flaresolver, cloudflare, solver, bypass, protection, solving, library, cloudflaresolver, delegatinghandler, recaptcha, captcha, javascript, challenge, utilities