0

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.

w4po
  • 41
  • 8
  • [Only one is allowed](https://www.rfc-editor.org/rfc/rfc6265#section-5.4). Why do you need to send separate headers? – Crowcoder Jul 20 '22 at 12:35
  • @Crowcoder I am working on a website that requires me to send the request with separate cookie headers, I've noticed that regular browsers send cookies as separate headers, but in .NET I can't find a way to do that yet. – w4po Jul 20 '22 at 13:08
  • You could try setting headers with name "cookie" instead of using a cookie container. One of the [answers here](https://stackoverflow.com/questions/12373738/how-do-i-set-a-cookie-on-httpclients-httprequestmessage) mentions you have to disable cookie containers first. – Crowcoder Jul 20 '22 at 13:40
  • Same thing but this time cookies are grouped by a Comma ',' – w4po Jul 22 '22 at 02:30

0 Answers0