Questions tagged [cookiecontainer]

Provides a container for a collection of CookieCollection objects.

In C#:

A CookieContainer is a data structure that provides storage for instances of the Cookie class, and which is accessed in a database-like manner. The CookieContainer has a capacity limit that is set when the container is created or changed by a property.

One might use a CookieContainer in conjunction with a CookieCollection object for persisting HTTP cookies between HttpWebRequests and HttpWebResponses.

Some example usage:

CookieContainer container = new CookieContainer();
CookieCollection cookies = new CookieCollection();

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://somesite.com/login");
request.CookieContainer = container;

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cookies = response.Cookies; // capture the cookies from the response

request = (HttpWebRequest)WebRequest.Create("http://somesite.com/profile");
request.CookieContainer = container;
// capture the cookies from the response for sending with a request
request.CookieContainer.Add(cookies);

response = (HttpWebResponse)request.GetResponse();
// capture the cookies from the response for sending with a request
cookies = response.Cookies; 
107 questions
0
votes
1 answer

Use CookieContainer with WebBrowser control?

I've created a CookieContainer and stored the cookies from a HttpWebRequest in it. Is there a way I can use this CookieContainer on a WebBrowser control? Thanks for the help.
Joey Morani
  • 25,431
  • 32
  • 84
  • 131