Search code examples
c#.netsystem.net.net-4.8

How do I add cookies to a webclient?


So I was looking for an answer and everything I've looked for hasn't worked.

I'm using WinForms with .NET Framework 4.8

I'm very confused as to this. Anyone able to help? Code below is just an example of what I need it to be used with.

WebClient client = new WebClient();
client.DownloadString("https://example.com");

Let's assume that the cookie's name is "USERID" and the ID is "HA-49"


Solution

  • As Çöđěxěŕ said.

    client.Headers.Add(HttpRequestHeader.Cookie,"USERID=HA-49");
    

    This indeed works.