据我了解,CookieContainer通过HttpWebRequests持久化cookie的基本用法如下:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
CookieContainer cookies = new CookieContainer();
request.CookieContainer = cookies;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
// Do stuff with response
}
然后:
request = (HttpWebRequest)WebRequest.Create(new url);
request.CookieContainer = cookies;
etc...
但我无法理解这个过程背后的逻辑。变量 cookies 在初始化后似乎没有在任何地方重新分配。第一个 WebResponse 中的 cookie 究竟是如何进入第二个 WebRequest 的?