C# CookieContainer send multiple 'cookie' header instead of just one grouped header

241 Views Asked by At

So I am trying to send an HTTP request with a CookieContainer via HttpClient, HttpWebRequest...,

But the request is sent with a grouped cookie header like this:

Cookie: PHPSESSID=1234567; another_cookie=abcdef

But I need it to be in a separate cookie header like this:

Cookie: PHPSESSID=1234567
Cookie: another_cookie=abcdef

I've tried to use Harmony to patch the GetCookieHeader method
to replace "; " with $"{Environment.NewLine}Cookie: ":

[HarmonyPatch(typeof(CookieContainer))]
[HarmonyPatch("GetCookieHeader", new[] { typeof(Uri), typeof(string) }, new[] { ArgumentType.Normal, ArgumentType.Out })]
class Patch01
{
    static void Postfix(ref string __result)
    {
        __result = __result?.Replace("; ", $"{Environment.NewLine}Cookie: ");
    }
}

But it didn't work and the request is still sent with one cookie header.

I really appreciate any help you can provide.
Thanks.

0

There are 0 best solutions below