According to MSDN CookieContainer.SetCookies
should
Adds Cookie instances for one or more cookies from an HTTP cookie header to the CookieContainer for a specific URI
which implies that it should work for multiple cookies, but when I do
_cookieContainer.SetCookies(new Uri("http://localhost"), "a=a;b=b");
and later try to retrieve the cookies using
_cookieContainer.GetCookies(new Uri("http://localhost"));
I only get one cookie entry which is a=a
I thought it might be that the cookie header format is wrong, so I manually added two cookies using .Add
method, and later try to get the header by calling .GetCookieHeader
, I get exactly the same string "a=a;b=b"
.
Did I miss anything or did I just find a .NET bug? I am currently using
VS2015 - v14.0.23107.0,
.NET - 4.6 4.6.00081
Why don't you try to pass the second parameter the same way as MSDN suggests on the documentation site of SetCookies
:
cookieHeader
Type: System.String
The contents of an HTTP set-cookie header as returned by a HTTP server, with Cookie instances delimited by commas.
_cookieContainer.SetCookies(new Uri("http://localhost"), "a=a,b=b");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With