-
Notifications
You must be signed in to change notification settings - Fork 32
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
Added cookies support #26
base: master
Are you sure you want to change the base?
Conversation
Hello! @ilike2burnthing you've asked me to provide some test code here for this and #27. I did come back with a reply, albeit late, and I'm assuming you didn't get notified about it since the PR was merged. I'm reposting here: Make sure you're using .NET8 when compiling! using FlareSolverrSharp.Solvers;
using FlareSolverrSharp.Types;
using System.Reflection;
namespace Playground
{
class Program
{
static async Task Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine($"Usage: dotnet run {Assembly.GetExecutingAssembly().Location} <FlareSolverr URL>");
return;
}
FlareSolverr solver = new(args[0]);
FlareSolverrIndexResponse indexResponse = await solver.GetIndex();
Console.WriteLine("GetIndex() returned the following:");
Console.WriteLine($" Message = '{indexResponse.Message}'");
Console.WriteLine($" Version = '{indexResponse.Version}'");
Console.WriteLine($" UserAgent = '{indexResponse.UserAgent}'");
Console.WriteLine("Now, I'll save the UserAgent and use it WITHOUT having to call Solve() and do an expensive request.\n");
// Code that uses indexResponse.UserAgent goes here
Uri uri = new("https://setcookie.net/");
HttpRequestMessage request = new(HttpMethod.Get, uri);
Console.WriteLine($"Calling Solve() on {uri} with no cookies...");
FlareSolverrResponse response = await solver.Solve(request);
if (response.Solution.Response.Contains("Received no cookies."))
{
Console.WriteLine("Received no cookies, as expected.");
}
else
{
Console.WriteLine("Received cookies, which is unexpected!");
}
Console.WriteLine($"Calling Solve() on {uri} with 2 cookies...");
response = await solver.Solve(request, cookies: [
new Cookie() { Name = "test", Value = "value" },
new Cookie() { Name = "test2", Value = "value2" }
]);
if (response.Solution.Response.Contains("Received no cookies."))
{
Console.WriteLine("Received no cookies, which is unexpected!");
}
else if (response.Solution.Response.Contains("test = value") &&
response.Solution.Response.Contains("test2 = value2"))
{
Console.WriteLine("Received cookies, as expected.");
}
else
{
Console.WriteLine($"Something went wrong, here's the response:\n{response.Solution.Response}");
}
}
}
} |
Apologies, I did see it, and I thought I'd replied with at least a 'thanks', but seemingly not. My focus at the time (I need to go back to it actually) was with FlareSolverr/FlareSolverr#1163. I'll deal with this ASAP. |
Adds support for FlareSolverr v3.2.0's cookies.