有没有办法清除 CookieContainer?

der*_*khh 4 c# cookies httpclient

我想清除 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);
Run Code Online (Sandbox Code Playgroud)

小智 6

The only solution I know is to expire all cookies:

        cc.GetCookies(new Uri(...))
            .Cast<Cookie>()
            .ToList()
            .ForEach(c => c.Expired = true);
Run Code Online (Sandbox Code Playgroud)