本文整理汇总了C#中System.Net.CookieContainer.RemoveCookie方法的典型用法代码示例。如果您正苦于以下问题:C# CookieContainer.RemoveCookie方法的具体用法?C# CookieContainer.RemoveCookie怎么用?C# CookieContainer.RemoveCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.CookieContainer
的用法示例。
在下文中一共展示了CookieContainer.RemoveCookie方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestRemoveCookies
public void TestRemoveCookies()
{
var cookieContainer = new CookieContainer();
var uri1 = new Uri("http://localhost/");
var cookie1 = new Cookie("abc1", "123");
var cookie2 = new Cookie("abc2", "234");
cookieContainer.Add(uri1, cookie1);
cookieContainer.Add(uri1, cookie2);
var uri2 = new Uri("http://google.com/");
var cookie3 = new Cookie("abc3", "345");
var cookie4 = new Cookie(cookie2.Name, "456");
cookieContainer.Add(uri2, cookie3);
cookieContainer.Add(uri2, cookie4);
var resultAddedCookies = cookieContainer.GetCookies().OrderBy(t => t.Name).ThenBy(t => t.Value).ToArray();
var expectedAddedCookies = new[] { cookie1, cookie2, cookie4, cookie3 };
AssertUtil.SequenceEqual(expectedAddedCookies, resultAddedCookies, (x, y) => x.Name == y.Name && x.Value == y.Value);
cookieContainer.RemoveCookie(cookie2.Name);
var resultRemainingCookies = cookieContainer.GetCookies().OrderBy(t => t.Name).ThenBy(t => t.Value).ToArray();
var expectedRemainingCookies = new[] { cookie1, cookie3 };
AssertUtil.SequenceEqual(expectedRemainingCookies, resultRemainingCookies, (x, y) => x.Name == y.Name && x.Value == y.Value);
}