Skip to content

Conversation

FFace32
Copy link
Contributor

@FFace32 FFace32 commented Oct 10, 2023

Adds support for FlareSolverr v3.2.0's cookies.

@FFace32 FFace32 mentioned this pull request Mar 1, 2024
@FFace32
Copy link
Contributor Author

FFace32 commented Jun 1, 2024

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}");
            }
        }
    }
}

@ilike2burnthing
Copy link
Contributor

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.

Decimation added a commit to Decimation/FlareSolverrSharp that referenced this pull request Oct 23, 2024
Decimation added a commit to Decimation/FlareSolverrSharp that referenced this pull request Oct 23, 2024
Decimation added a commit to Decimation/FlareSolverrSharp that referenced this pull request Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants