c# - 有没有办法清除 CookieContainer?

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

最佳答案

我知道的唯一解决方案是使所有 cookie 过期:

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

关于c# - 有没有办法清除 CookieContainer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33025549/

相关文章:

c# - 如何从 System.Drawing.Imaging.ImageFormat 获取 contentType

c# - VS2017 不显示建议并且无法导航到插入符号下的符号

PHP setcookie() 奇怪的行为

java - Struts2登录管理和授权

c# - 在 UWP(W10) 中使用 HttpClient 发出 POST 请求

android - Titanium,等待 HTTPClient 回复

c# - 实现 IValueConverter 将字符串转换为图像

spring-mvc - 如何使用 spring-restdoc 记录 cookie?

Android DefaultHttpClient HttpResponse 缺少 Set-Cookie header 字段

c# - 如何按 child 的 child 的数量在 EF parent 中排序?