我想清除 CookieContainer 中收到的所有 cookie,而不需要初始化新的 CookieContainer、HttpClientHandler 和 HttpClient。有办法吗?我检查过MSDN但似乎我只能使用 GetCookies(Uri) 来获取与特定 Uri 关联的所有 cookie。
var cc = new CookieContainer();
var handler = new HttpClientHandler
{
CookieContainer = cc
};
var client = new HttpClient(handler);
最佳答案
我知道的唯一解决方案是使所有 cookie 过期:
cc.GetCookies(new Uri(...))
.Cast<Cookie>()
.ToList()
.ForEach(c => c.Expired = true);
关于c# - 有没有办法清除 CookieContainer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33025549/