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


C# Cookie.ToString方法代码示例

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


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

示例1: PublicFields

		public void PublicFields ()
		{
			Cookie c = new Cookie ();
			Assert.AreEqual (string.Empty, c.Name, "#A1");
			Assert.AreEqual (string.Empty, c.Value, "#A2");
			Assert.AreEqual (string.Empty, c.Domain, "#A3");
			Assert.AreEqual (string.Empty, c.Port, "#A4");
			Assert.AreEqual (string.Empty, c.Comment, "#A5");
			Assert.AreEqual (null, c.CommentUri, "#A6");
			Assert.IsFalse (c.Discard, "#A7");
			Assert.IsFalse (c.Expired, "#A8");
			Assert.AreEqual (DateTime.MinValue, c.Expires, "#A9");
			Assert.IsFalse (c.HttpOnly, "#A10");
			Assert.AreEqual (string.Empty, c.Path, "#A11");
			Assert.IsFalse (c.Secure, "#A12");
			Assert.AreEqual (0, c.Version, "#A13");
			Assert.AreEqual (string.Empty, c.ToString (), "#A14");

			c.Expires = DateTime.Now;
			Assert.IsTrue (c.Expired, "#A15");

			c.Port = null;
			Assert.AreEqual (string.Empty, c.Port, "#A16");

			c.Value = null;
			Assert.AreEqual (string.Empty, c.Value, "#A17");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:27,代码来源:CookieTest.cs

示例2: ExHentaiConnection

        private ExHentaiConnection()
        {
            wc = new WebClient();

            HatHConfig.Load(System.IO.Directory.GetCurrentDirectory() + "/settings.ini");

            string uid = HatHConfig.UserID;
            string passhash = HatHConfig.PassHash;

            Cookie id = new Cookie("ipb_member_id", uid, "/", ".exhentai.org");
            Cookie pass = new Cookie("ipb_pass_hash", passhash, "/", ".exhentai.org");
            wc.Headers.Add(HttpRequestHeader.Cookie, id.ToString() + ";" + pass.ToString());
        }
开发者ID:p1nkc0de,项目名称:hathCacheRipper,代码行数:13,代码来源:ExHentaiConnection.cs

示例3: ExeTest

 private void ExeTest()
 {
     if (QueProxy.Count == 0)
     {
         btnStartTest.Enabled = true;
         return;
     }
     string proxy = QueProxy.Dequeue();
     Cookie coki = new Cookie(CookieId.ToString(), Cookie_P1 + CookieId + "; " + Cookie_P2 + CookieId, Application.StartupPath + "\\Cookie", "/");
     Core.Core.InternetSetCookie(TestUrl, null, coki.ToString() + "; expires = Sun, 01-Jan-2017 00:00:00 GMT");
     Core.Core.RefreshIESettings(proxy);
     wb.Tag = proxy;
     wb.Navigate(TestUrl);
     tmr.Start();
 }
开发者ID:EgyFalseX,项目名称:CraigslistTools,代码行数:15,代码来源:TestProxyUC.cs

示例4: ExeFlag

        private void ExeFlag()
        {
            //var t = new System.Threading.Thread(() =>
            //{

            //});
            //t.SetApartmentState(System.Threading.ApartmentState.STA);
            //t.Start();

            if (_flagQue.Count == 0) return;
            Datasource.FlagUnit flag = _flagQue.Dequeue();
            while (!flag.Exe)
                flag = _flagQue.Dequeue();
            WebBrowser _flagBrowser = new WebBrowser();
            _flagBrowser.DocumentCompleted += _flagBrowser_DocumentCompleted;
            Cookie coki = new Cookie("Cookie" + flag.PID, flag.Proxy + flag.AgentId + flag.PID, Application.StartupPath + "/Cookie", "/");
            Core.Core.InternetSetCookie(flag.Url, null, coki.ToString() + "; expires = Sun, 01-Jan-2017 00:00:00 GMT");

            ChangeUserAgent(flag.Agent);
            Core.Core.RefreshIESettings(flag.Proxy);
            _flagBrowser.Tag = flag;
            _tmr_flag.Tag = _flagBrowser;
            System.Threading.Thread.Sleep(1000 * 3);
            _tmr_flag.Start();
            _flagBrowser.Navigate(flag.Url);
        }
开发者ID:EgyFalseX,项目名称:CraigslistTools,代码行数:26,代码来源:AdFlager_ProxyUC.cs

示例5: Add

 internal void Add(Cookie cookie, bool throwOnError)
 {
     if (cookie.Value.Length > this.m_maxCookieSize)
     {
         if (throwOnError)
         {
             throw new CookieException(SR.GetString("net_cookie_size", new object[] { cookie.ToString(), this.m_maxCookieSize }));
         }
     }
     else
     {
         try
         {
             PathList list = (PathList) this.m_domainTable[cookie.DomainKey];
             if (list == null)
             {
                 list = new PathList();
                 this.AddRemoveDomain(cookie.DomainKey, list);
             }
             int cookiesCount = list.GetCookiesCount();
             CookieCollection cookies = (CookieCollection) list[cookie.Path];
             if (cookies == null)
             {
                 cookies = new CookieCollection();
                 list[cookie.Path] = cookies;
             }
             if (cookie.Expired)
             {
                 lock (cookies)
                 {
                     int index = cookies.IndexOf(cookie);
                     if (index != -1)
                     {
                         cookies.RemoveAt(index);
                         this.m_count--;
                     }
                     return;
                 }
             }
             if (((cookiesCount < this.m_maxCookiesPerDomain) || this.AgeCookies(cookie.DomainKey)) && ((this.m_count < this.m_maxCookies) || this.AgeCookies(null)))
             {
                 lock (cookies)
                 {
                     this.m_count += cookies.InternalAdd(cookie, true);
                 }
             }
         }
         catch (Exception exception)
         {
             if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
             {
                 throw;
             }
             if (throwOnError)
             {
                 throw new CookieException(SR.GetString("net_container_add_cookie"), exception);
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:60,代码来源:CookieContainer.cs

示例6: Add

        // This method is called *only* when cookie verification is done, so unlike with public
        // Add(Cookie cookie) the cookie is in a reasonable condition.
        internal void Add(Cookie cookie, bool throwOnError)
        {
            PathList pathList;

            if (cookie.Value.Length > _maxCookieSize)
            {
                if (throwOnError)
                {
                    throw new CookieException(SR.Format(SR.net_cookie_size, cookie.ToString(), _maxCookieSize));
                }
                return;
            }

            try
            {
                lock (_domainTable)
                {
                    _domainTable.TryGetValue(cookie.DomainKey, out pathList);
                    if (pathList == null)
                    {
                        pathList = new PathList();
                        AddRemoveDomain(cookie.DomainKey, pathList);
                    }
                }
                int domain_count = pathList.GetCookiesCount();

                CookieCollection cookies;
                lock (pathList.SyncRoot)
                {
                    cookies = (CookieCollection)pathList[cookie.Path];

                    if (cookies == null)
                    {
                        cookies = new CookieCollection();
                        pathList[cookie.Path] = cookies;
                    }
                }

                if (cookie.Expired)
                {
                    // Explicit removal command (Max-Age == 0)
                    lock (cookies)
                    {
                        int idx = cookies.IndexOf(cookie);
                        if (idx != -1)
                        {
                            cookies.RemoveAt(idx);
                            --_count;
                        }
                    }
                }
                else
                {
                    // This is about real cookie adding, check Capacity first
                    if (domain_count >= _maxCookiesPerDomain && !AgeCookies(cookie.DomainKey))
                    {
                        return; // Cannot age: reject new cookie
                    }
                    else if (_count >= _maxCookies && !AgeCookies(null))
                    {
                        return; // Cannot age: reject new cookie
                    }

                    // About to change the collection
                    lock (cookies)
                    {
                        _count += cookies.InternalAdd(cookie, true);
                    }
                }
            }
            catch (OutOfMemoryException)
            {
                throw;
            }
            catch (Exception e)
            {
                if (throwOnError)
                {
                    throw new CookieException(SR.net_container_add_cookie, e);
                }
            }
        }
开发者ID:rainersigwald,项目名称:corefx,代码行数:84,代码来源:CookieContainer.cs

示例7: GetDirectConnectionByCookie

        /// <summary>
        /// Gets a <see cref="DirectConnection"/> by its Rendezvous cookie
        /// </summary>
        /// <returns>The <see cref="DirectConnection"/> that corresponds to the cookie, or null if no corresponding DC is found</returns>
        public DirectConnection GetDirectConnectionByCookie(Cookie key, bool removefromcache)
        {
            DirectConnection retval = null;
            foreach (DirectConnection dc in _directconnections)
            {
                if(dc.Cookie.ToString() == key.ToString())
                {
                    retval = dc;
                    break;
                }
            }

            if (retval != null && removefromcache)
            {
                _directconnections.Remove(retval);
            }

            return retval;
        }
开发者ID:pkt30,项目名称:OscarLib,代码行数:23,代码来源:ConnectionManager.cs

示例8: GetHttpHeader

        private static string GetHttpHeader(Cookie cookie, string domainOverride = null)
        {
            var cookieHeader = new StringBuilder(1024);

            cookieHeader.AppendFormat("{0}={1}", cookie.Name, cookie.Value);

            // Workaround for bug in Cookie.ToString() which fails to includes the path
            // and domain attributes unless you temporarily set the cookie version to 1.
            if (cookie.Version == 0)
            {
                cookie.Version = 1;
                cookie.Version = 0;
            }

            var cookieString = cookie.ToString();

            if (cookieString.Contains("$Domain=") && !string.IsNullOrWhiteSpace(cookie.Domain))
            {
                cookieHeader.AppendFormat("; Domain={0}", domainOverride ?? cookie.Domain);
            }

            if (!string.IsNullOrWhiteSpace(cookie.Path))
            {
                cookieHeader.AppendFormat("; Path={0}", cookie.Path);
            }

            if (cookie.Expires != DateTime.MinValue)
            {
                var utcExpires = cookie.Expires.Kind == DateTimeKind.Local ? cookie.Expires.ToUniversalTime() : cookie.Expires;
                cookieHeader.AppendFormat("; Expires={0:R}", utcExpires);
            }

            if (!string.IsNullOrWhiteSpace(cookie.Comment))
            {
                cookieHeader.AppendFormat("; Comment={0}", cookie.Comment);
            }

            if (cookie.CommentUri != null)
            {
                cookieHeader.AppendFormat("; CommentURL={0}", cookie.CommentUri);
            }

            if (cookie.HttpOnly)
            {
                cookieHeader.AppendFormat("; HttpOnly");
            }

            if (cookie.Secure && domainOverride == null)
            {
                cookieHeader.AppendFormat("; Secure");
            }

            if (cookie.Discard)
            {
                cookieHeader.AppendFormat("; Discard");
            }

            if (!string.IsNullOrWhiteSpace(cookie.Port))
            {
                cookieHeader.AppendFormat("; Port={0}", cookie.Port);
            }

            if (cookie.Version != 0)
            {
                cookieHeader.AppendFormat("; Version={0}", cookie.Version);
            }

            return cookieHeader.ToString();
        }
开发者ID:tstrimple,项目名称:DiscoveryEducation,代码行数:69,代码来源:CookieManager.cs

示例9: ToStringTest

		public void ToStringTest ()
		{
			Cookie c1 = new Cookie ("NAME", "VALUE", "/", "example.com");
			Assert.AreEqual ("NAME=VALUE", c1.ToString (), "#A1");

			Cookie c2 = new Cookie ();
			Assert.AreEqual (string.Empty, c2.ToString (), "#A2");

			Cookie c3 = new Cookie("NAME", "VALUE");
			Assert.AreEqual ("NAME=VALUE", c3.ToString (), "#A3");

			Cookie c4 = new Cookie ("NAME", "VALUE", "/", "example.com");
			c4.Version = 1;
			Assert.AreEqual ("$Version=1; NAME=VALUE; $Path=/; $Domain=example.com", c4.ToString (), "#A4");

			Cookie c5 = new Cookie ("NAME", "VALUE", "/", "example.com");
			c5.Port = "\"8080\"";
			Assert.AreEqual ("$Version=1; NAME=VALUE; $Path=/; $Domain=example.com; $Port=\"8080\"", c5.ToString (), "#A5");

			Cookie c6 = new Cookie ("NAME", "VALUE");
			c6.Version = 1;
			Assert.AreEqual ("$Version=1; NAME=VALUE", c6.ToString (), "#A6");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:23,代码来源:CookieTest.cs

示例10: Add

 internal void Add(Cookie cookie, bool throwOnError)
 {
     if (cookie.Value.Length > this.m_maxCookieSize)
       {
     if (!throwOnError)
       return;
     throw new CookieException(SR.GetString("net_cookie_size", (object) cookie.ToString(), (object) this.m_maxCookieSize));
       }
       else
       {
     try
     {
       PathList pathList = (PathList) this.m_domainTable[(object) cookie.DomainKey];
       if (pathList == null)
       {
     pathList = new PathList();
     this.AddRemoveDomain(cookie.DomainKey, pathList);
       }
       int cookiesCount = pathList.GetCookiesCount();
       CookieCollection cookieCollection = (CookieCollection) pathList[cookie.Path];
       if (cookieCollection == null)
       {
     cookieCollection = new CookieCollection();
     pathList[cookie.Path] = (object) cookieCollection;
       }
       if (cookie.Expired)
       {
     lock (cookieCollection)
     {
       int local_3 = cookieCollection.IndexOf(cookie);
       if (local_3 == -1)
         return;
       cookieCollection.RemoveAt(local_3);
       --this.m_count;
     }
       }
       else
       {
     if (cookiesCount >= this.m_maxCookiesPerDomain && !this.AgeCookies(cookie.DomainKey) || this.m_count >= this.m_maxCookies && !this.AgeCookies((string) null))
       return;
     lock (cookieCollection)
       this.m_count += cookieCollection.InternalAdd(cookie, true);
       }
     }
     catch (Exception ex)
     {
       if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException)
     throw;
       else if (throwOnError)
     throw new CookieException(SR.GetString("net_container_add_cookie"), ex);
     }
       }
 }
开发者ID:Alister742,项目名称:ParseKit,代码行数:53,代码来源:CookieContainer.cs

示例11: Add

        // This method is called *only* when cookie verification is done,
        // so unlike with public Add(Cookie cookie) the cookie is in sane condition
        internal void Add(Cookie cookie, bool throwOnError) {

            PathList pathList;

            if (cookie.Value.Length > m_maxCookieSize) {
                if (throwOnError) {
                    throw new CookieException(SR.GetString(SR.net_cookie_size, cookie.ToString(), m_maxCookieSize));
                }
                return;
            }

            try {

                pathList = (PathList)m_domainTable[cookie.DomainKey];
                if (pathList == null) {
                    pathList = new PathList();
                    AddRemoveDomain(cookie.DomainKey, pathList);
                }
                int domain_count = pathList.GetCookiesCount();

                CookieCollection cookies = (CookieCollection)pathList[cookie.Path];

                if (cookies == null) {
                    cookies = new CookieCollection();
                    pathList[cookie.Path] = cookies;
                }

                if(cookie.Expired) {
                    //Explicit removal command (Max-Age == 0)
                    lock (cookies) {
                        int idx = cookies.IndexOf(cookie);
                        if (idx != -1) {
                            cookies.RemoveAt(idx);
                            --m_count;
                        }
                    }
                }
                else {
                    //This is about real cookie adding, check Capacity first
                    if (domain_count >= m_maxCookiesPerDomain && !AgeCookies(cookie.DomainKey)) {
                            return; //cannot age -> reject new cookie
                    }
                    else if (this.m_count >= m_maxCookies && !AgeCookies(null)) {
                            return; //cannot age -> reject new cookie
                    }

                    //about to change the collection
                    lock (cookies) {
                        m_count += cookies.InternalAdd(cookie, true);
                    }
                }
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                    throw;
                }

                if (throwOnError) {
                    throw new CookieException(SR.GetString(SR.net_container_add_cookie), e);
                }
            }
            catch {
                if (throwOnError) {
                    throw new CookieException(SR.GetString(SR.net_container_add_cookie), new Exception(SR.GetString(SR.net_nonClsCompliantException)));
                }
            }
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:69,代码来源:cookiecontainer.cs

示例12: GetCookieHeader5b

		public void GetCookieHeader5b ()
		{
			CookieContainer cc = new CookieContainer ();
			Cookie cookie = new Cookie ("name1", "value1");
			cookie.Domain = "localhost";
			cookie.Comment = "Short name";
			cookie.Expires = DateTime.Now.Add (new TimeSpan (3, 2, 5));
			cookie.Version = 1;
			cc.Add (cookie);
			Assert.AreEqual ("$Version=1; name1=value1; $Domain=localhost", cookie.ToString (), "#E0");
			Assert.AreEqual ("$Version=1; name1=value1; $Path=/",
				cc.GetCookieHeader (new Uri ("http://localhost/path/sub")), "#E1");
		}
开发者ID:nestalk,项目名称:mono,代码行数:13,代码来源:CookieContainerTest.cs

示例13: Authenticate

        /// <summary>
        /// Authenticate to the dataImportAPI and get the <see cref="_jsessionID"/>
        /// </summary>
        private void Authenticate()
        {
            if (clusterHost == null) {
                ClusterLookup ();
            }

            string password = HttpUtility.UrlEncode(this.password);
            string url = String.Format ("{0}{1}/SpatialKeyFramework/dataImportAPI?action=login&orgName={2}&user={3}&password={4}",
                                       _protocol, clusterHost, organizationName, HttpUtility.UrlEncode (userName), password);
            Log(String.Format("Authenticate: {0}", url.Replace(password, "XXX")));

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create (url);
            request.Method = "GET";
            CookieContainer cookieJar = new CookieContainer ();
            request.CookieContainer = cookieJar;

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse ())
            using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
            {
                if (response.StatusCode != HttpStatusCode.OK) {
                    throw new SystemException ("Authentication Failed");
                }

                _jsessionID = cookieJar.GetCookies (request.RequestUri) ["JSESSIONID"];
                Log(streamReader.ReadToEnd());
            }

            Log(_jsessionID.ToString());
        }
开发者ID:rstehwien,项目名称:SpatialKeyDataAPICSharp,代码行数:32,代码来源:DataImporter.cs

示例14: ExeFlag

        private void ExeFlag()
        {
            //var t = new System.Threading.Thread(() => {   });
            //t.SetApartmentState(System.Threading.ApartmentState.STA);
            //t.Start();
            if (_maxIpUsage == _changeIPoffset)
            {
                Core.HMA.ChangeIP();
                System.Threading.Thread.Sleep(2000);
                while (Core.HMA.Status() == Core.HMA.HMA_State.Not_Connected)
                {
                    System.Threading.Thread.Sleep(1000);
                    Application.DoEvents();
                }
                _changeIPoffset = 0;
            }

            if (_flagoffset == _flagQue.Count)
            {
                _flagoffset = 0;
                _flagLoop++;
            }
            if (_flagLoop == _maxFlagLoop)
            {
                btnSearch.Enabled = btnStartFlag.Enabled = btnAddPID.Enabled = true; Application.DoEvents();
                MessageBox.Show("Flagging Completed ...", "Done ...", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            Datasource.FlagUnit flag = _flagQue[_flagoffset];
            _flagoffset++;
            while (!flag.Exe)
            {
                _flagoffset++;
                flag = _flagQue[_flagoffset];
            }
            WebBrowser _flagBrowser = new WebBrowser();
            _flagBrowser.DocumentCompleted += _flagBrowser_DocumentCompleted;
            Cookie coki = new Cookie("Cookie" + flag.PID, flag.Proxy + flag.AgentId + flag.PID, Application.StartupPath + "/Cookie", "/");
            Core.Core.InternetSetCookie(flag.Url, null, coki.ToString() + "; expires = Sun, 01-Jan-2017 00:00:00 GMT");

            ChangeUserAgent(flag.Agent);
            _flagBrowser.Tag = flag;
            _tmr_flag.Tag = _flagBrowser;
            //System.Threading.Thread.Sleep(1000 * 3);
            _tmr_flag.Start();
            _flagBrowser.Navigate(flag.Url);
            //_changeIPoffset++;
        }
开发者ID:EgyFalseX,项目名称:CraigslistTools,代码行数:48,代码来源:AdFlager_HMAUC.cs


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