当前位置: 首页>>代码示例>>C#>>正文


C# IE.GetCookie方法代码示例

本文整理汇总了C#中IE.GetCookie方法的典型用法代码示例。如果您正苦于以下问题:C# IE.GetCookie方法的具体用法?C# IE.GetCookie怎么用?C# IE.GetCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IE的用法示例。


在下文中一共展示了IE.GetCookie方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Should_set_and_get_cookies

        public void Should_set_and_get_cookies()
        {
            using (var ie = new IE())
            {
                // Clear all cookies.
                ie.ClearCookies();

                // Ensure our test cookies don't exist from a previous run.
                Assert.IsNull(ie.GetCookie("http://1.watin.com/", "test-cookie"));
                Assert.IsNull(ie.GetCookie("http://2.watin.com/", "test-cookie"));

                // Create cookies for a pair of domains.
                ie.SetCookie("http://1.watin.com/", "test-cookie=abc; expires=Wed, 01-Jan-2020 00:00:00 GMT");
                Assert.AreEqual("test-cookie=abc", ie.GetCookie("http://1.watin.com/", "test-cookie"));

                ie.SetCookie("http://2.watin.com/", "test-cookie=def; expires=Wed, 01-Jan-2020 00:00:00 GMT");
                Assert.AreEqual("test-cookie=def", ie.GetCookie("http://2.watin.com/", "test-cookie"));

                CookieCollection collection = ie.GetCookiesForUrl(new Uri("http://2.watin.com/"));
                Assert.AreEqual(1, collection.Count);
                Assert.AreEqual(collection[0].Name, "test-cookie");
                Assert.AreEqual(collection[0].Value, "def");
            }
        }
开发者ID:koshdim,项目名称:KoWatIn,代码行数:24,代码来源:IETests.cs

示例2: Should_clear_cookies

        public void Should_clear_cookies()
        {
            using (var ie = new IE())
            {
                // Clear all cookies.
                ie.ClearCookies();

                // Ensure our test cookies don't exist from a previous run.
                Assert.IsNull(ie.GetCookie("http://1.watin.com/", "test-cookie"), "Expected no cookies for 1.watin.com");
                Assert.IsNull(ie.GetCookie("http://2.watin.com/", "test-cookie"), "Expected no cookies for 2.watin.com");

                // Create cookies for a pair of domains.
                ie.SetCookie("http://1.watin.com/", "test-cookie=abc; expires=Wed, 01-Jan-2020 00:00:00 GMT");
                ie.SetCookie("http://2.watin.com/", "test-cookie=def; expires=Wed, 01-Jan-2020 00:00:00 GMT");

                // Clear cookies under one subdomain.
                ie.ClearCookies("http://1.watin.com/");

                // Ensure just the cookie of the first subdomain was deleted.
                Assert.IsNull(ie.GetCookie("http://1.watin.com/", "test-cookie"), "Expected no cookies for 1.watin.com after clear");
                Assert.AreEqual("test-cookie=def", ie.GetCookie("http://2.watin.com/", "test-cookie"), "Expected cookie for 2.watin.com");

                // Clear cookies under master domain.
                ie.ClearCookies("http://watin.com/");

                // Ensure the second subdomain's cookie was deleted this time.
                Assert.IsNull(ie.GetCookie("http://2.watin.com/", "test-cookie"), "Expected no cookies for 2.watin.com after ClearCookies");
            }
        }
开发者ID:koshdim,项目名称:KoWatIn,代码行数:29,代码来源:IETests.cs


注:本文中的IE.GetCookie方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。