I think you are looking for the CookieContainer class. If I understand what you're trying to do right, you have separate objects for the request and response, and you want to automatically transfer the collection of response files to the next request cookie collection. Try using this code:
CookieContainer cookieJar = new CookieContainer(); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.google.com"); request.CookieContainer = cookieJar; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); int cookieCount = cookieJar.Count;
Once you create a cookieJar and set it into a cookie Cookie, it will store all cookies that come from the response, so in the example above the number of cookie jugs will be 1 after it visits Google.com.The properties of the request and response cookie container will be higher contain a pointer to a cookieJar, so cookies are automatically processed and shared between objects.
Dan Herbert Feb 21 '09 at 3:44 2009-02-21 03:44
source share