有没有办法清除CookieContainer?

时间:2015-10-08 20:38:52

标签: 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);

1 个答案:

答案 0 :(得分:2)

我知道的唯一解决方案是使所有Cookie失效:

        cc.GetCookies(new Uri(...))
            .Cast<Cookie>()
            .ToList()
            .ForEach(c => c.Expired = true);