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


C# CookieCollection.InternalAdd方法代码示例

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


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

示例1: CookieCutter

 internal CookieCollection CookieCutter(Uri uri, string headerName, string setCookieHeader, bool isThrow)
 {
     CookieCollection cookies = new CookieCollection();
     CookieVariant unknown = CookieVariant.Unknown;
     if (headerName == null)
     {
         unknown = CookieVariant.Rfc2109;
     }
     else
     {
         for (int i = 0; i < HeaderInfo.Length; i++)
         {
             if (string.Compare(headerName, HeaderInfo[i].Name, StringComparison.OrdinalIgnoreCase) == 0)
             {
                 unknown = HeaderInfo[i].Variant;
             }
         }
     }
     bool isLocalDomain = this.IsLocalDomain(uri.Host);
     try
     {
         Cookie cookie;
         CookieParser parser = new CookieParser(setCookieHeader);
     Label_0060:
         cookie = parser.Get();
         if (cookie != null)
         {
             if (ValidationHelper.IsBlankString(cookie.Name))
             {
                 if (isThrow)
                 {
                     throw new CookieException(SR.GetString("net_cookie_format"));
                 }
             }
             else if (cookie.VerifySetDefaults(unknown, uri, isLocalDomain, this.m_fqdnMyDomain, true, isThrow))
             {
                 cookies.InternalAdd(cookie, true);
             }
             goto Label_0060;
         }
     }
     catch (Exception exception)
     {
         if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
         {
             throw;
         }
         if (isThrow)
         {
             throw new CookieException(SR.GetString("net_cookie_parse_header", new object[] { uri.AbsoluteUri }), exception);
         }
     }
     foreach (Cookie cookie2 in cookies)
     {
         this.Add(cookie2, isThrow);
     }
     return cookies;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:58,代码来源:CookieContainer.cs

示例2: MergeUpdateCollections

 private void MergeUpdateCollections(CookieCollection destination, CookieCollection source, int port, bool isSecure, bool isPlainOnly)
 {
     lock (source)
     {
         for (int i = 0; i < source.Count; i++)
         {
             bool flag = false;
             Cookie cookie = source[i];
             if (cookie.Expired)
             {
                 source.RemoveAt(i);
                 this.m_count--;
                 i--;
                 continue;
             }
             if (!isPlainOnly || (cookie.Variant == CookieVariant.Plain))
             {
                 if (cookie.PortList != null)
                 {
                     foreach (int num2 in cookie.PortList)
                     {
                         if (num2 == port)
                         {
                             flag = true;
                             break;
                         }
                     }
                 }
                 else
                 {
                     flag = true;
                 }
             }
             if (cookie.Secure && !isSecure)
             {
                 flag = false;
             }
             if (flag)
             {
                 destination.InternalAdd(cookie, false);
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:44,代码来源:CookieContainer.cs

示例3: MergeUpdateCollections

        private void MergeUpdateCollections(CookieCollection destination, CookieCollection source, int port, bool isSecure, bool isPlainOnly)
        {
            lock (source)
            {
                // Cannot use foreach as we going update 'source'
                for (int idx = 0; idx < source.Count; ++idx)
                {
                    bool to_add = false;

                    Cookie cookie = source[idx];

                    if (cookie.Expired)
                    {
                        // If expired, remove from container and don't add to the destination
                        source.RemoveAt(idx);
                        --_count;
                        --idx;
                    }
                    else
                    {
                        // Add only if port does match to this request URI
                        // or was not present in the original response.
                        if (isPlainOnly && cookie.Variant != CookieVariant.Plain)
                        {
                            ; // Don't add
                        }
                        else if (cookie.PortList != null)
                        {
                            foreach (int p in cookie.PortList)
                            {
                                if (p == port)
                                {
                                    to_add = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            // It was implicit Port, always OK to add.
                            to_add = true;
                        }

                        // Refuse to add a secure cookie into an 'unsecure' destination
                        if (cookie.Secure && !isSecure)
                        {
                            to_add = false;
                        }

                        if (to_add)
                        {
                            // In 'source' are already orederd.
                            // If two same cookies come from different 'source' then they
                            // will follow (not replace) each other.
                            destination.InternalAdd(cookie, false);
                        }
                    }
                }
            }
        }
开发者ID:rainersigwald,项目名称:corefx,代码行数:60,代码来源:CookieContainer.cs

示例4: ParseCookies

 private CookieCollection ParseCookies(Uri uri, string setCookieHeader)
 {
     Cookie cookie;
     CookieCollection cookies = new CookieCollection();
     CookieParser parser = new CookieParser(setCookieHeader);
 Label_000D:
     cookie = parser.GetServer();
     if (cookie != null)
     {
         if (cookie.Name.Length != 0)
         {
             cookies.InternalAdd(cookie, true);
         }
         goto Label_000D;
     }
     return cookies;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:17,代码来源:HttpListenerRequest.cs

示例5: CookieCutter

        internal CookieCollection CookieCutter(Uri uri, string headerName, string setCookieHeader, bool isThrow)
        {
            GlobalLog.Print("CookieContainer#" + Logging.HashString(this) + "::CookieCutter() uri:" + uri + " headerName:" + headerName + " setCookieHeader:" + setCookieHeader + " isThrow:" + isThrow);
            CookieCollection cookies = new CookieCollection();
            CookieVariant variant = CookieVariant.Unknown;
            if (headerName == null)
            {
                variant = CookieVariant.Default;
            }
            else
            {
                for (int i = 0; i < s_headerInfo.Length; ++i)
                {
                    if ((String.Compare(headerName, s_headerInfo[i].Name, StringComparison.OrdinalIgnoreCase) == 0))
                    {
                        variant = s_headerInfo[i].Variant;
                    }
                }
            }

            bool isLocalDomain = IsLocalDomain(uri.Host);
            try
            {
                CookieParser parser = new CookieParser(setCookieHeader);
                do
                {
                    Cookie cookie = parser.Get();
                    GlobalLog.Print("CookieContainer#" + Logging.HashString(this) + "::CookieCutter() CookieParser returned cookie:" + Logging.ObjectToString(cookie));
                    if (cookie == null)
                    {
                        break;
                    }

                    // Parser marks invalid cookies this way
                    if (String.IsNullOrEmpty(cookie.Name))
                    {
                        if (isThrow)
                        {
                            throw new CookieException(SR.net_cookie_format);
                        }
                        // Otherwise, ignore (reject) cookie
                        continue;
                    }

                    // This will set the default values from the response URI
                    // AND will check for cookie validity
                    if (!cookie.VerifySetDefaults(variant, uri, isLocalDomain, _fqdnMyDomain, true, isThrow))
                    {
                        continue;
                    }
                    // If many same cookies arrive we collapse them into just one, hence setting
                    // parameter isStrict = true below
                    cookies.InternalAdd(cookie, true);
                } while (true);
            }
            catch (OutOfMemoryException)
            {
                throw;
            }
            catch (Exception e)
            {
                if (isThrow)
                {
                    throw new CookieException(SR.Format(SR.net_cookie_parse_header, uri.AbsoluteUri), e);
                }
            }

            foreach (Cookie c in cookies)
            {
                Add(c, isThrow);
            }

            return cookies;
        }
开发者ID:rainersigwald,项目名称:corefx,代码行数:74,代码来源:CookieContainer.cs

示例6: ParseCookies

 private CookieCollection ParseCookies(Uri uri, string setCookieHeader) {
     GlobalLog.Print("HttpListenerRequest#" + ValidationHelper.HashString(this) + "::ParseCookies() uri:" + uri + " setCookieHeader:" + setCookieHeader);
     CookieCollection cookies = new CookieCollection();
     CookieParser parser = new CookieParser(setCookieHeader);
     for (;;) {
         Cookie cookie = parser.GetServer();
         GlobalLog.Print("HttpListenerRequest#" + ValidationHelper.HashString(this) + "::ParseCookies() CookieParser returned cookie:" + ValidationHelper.ToString(cookie));
         if (cookie==null) {
             // EOF, done.
             break;
         }
         if (cookie.Name.Length==0) {
             continue;
         }
         cookies.InternalAdd(cookie, true);
     }
     return cookies;
 }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:18,代码来源:HttpListenerRequest.cs

示例7: MergeUpdateCollections

 private void MergeUpdateCollections(CookieCollection destination, CookieCollection source, int port, bool isSecure, bool isPlainOnly)
 {
     lock (source)
       {
     for (int local_0 = 0; local_0 < source.Count; ++local_0)
     {
       bool local_1 = false;
       Cookie local_2 = source[local_0];
       if (local_2.Expired)
       {
     source.RemoveAt(local_0);
     --this.m_count;
     --local_0;
       }
       else
       {
     if (!isPlainOnly || local_2.Variant == CookieVariant.Plain)
     {
       if (local_2.PortList != null)
       {
         foreach (int item_0 in local_2.PortList)
         {
           if (item_0 == port)
           {
             local_1 = true;
             break;
           }
         }
       }
       else
         local_1 = true;
     }
     if (local_2.Secure && !isSecure)
       local_1 = false;
     if (local_1)
       destination.InternalAdd(local_2, false);
       }
     }
       }
 }
开发者ID:Alister742,项目名称:ParseKit,代码行数:40,代码来源:CookieContainer.cs

示例8: CookieCutter

 internal CookieCollection CookieCutter(Uri uri, string headerName, string setCookieHeader, bool isThrow)
 {
     CookieCollection cookieCollection = new CookieCollection();
       CookieVariant variant = CookieVariant.Unknown;
       if (headerName == null)
       {
     variant = CookieVariant.Rfc2109;
       }
       else
       {
     for (int index = 0; index < CookieContainer.HeaderInfo.Length; ++index)
     {
       if (string.Compare(headerName, CookieContainer.HeaderInfo[index].Name, StringComparison.OrdinalIgnoreCase) == 0)
     variant = CookieContainer.HeaderInfo[index].Variant;
     }
       }
       bool isLocalDomain = this.IsLocalDomain(uri.Host);
       try
       {
     CookieParser cookieParser = new CookieParser(setCookieHeader);
     while (true)
     {
       Cookie cookie;
       do
       {
     cookie = cookieParser.Get();
     if (cookie != null)
     {
       if (ValidationHelper.IsBlankString(cookie.Name))
       {
         if (isThrow)
           throw new CookieException(SR.GetString("net_cookie_format"));
       }
     }
     else
       goto label_19;
       }
       while (!cookie.VerifySetDefaults(variant, uri, isLocalDomain, this.m_fqdnMyDomain, true, isThrow));
       cookieCollection.InternalAdd(cookie, true);
     }
       }
       catch (Exception ex)
       {
     if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException)
       throw;
     else if (isThrow)
       throw new CookieException(SR.GetString("net_cookie_parse_header", new object[1]
       {
     (object) uri.AbsoluteUri
       }), ex);
       }
     label_19:
       foreach (Cookie cookie in cookieCollection)
     this.Add(cookie, isThrow);
       return cookieCollection;
 }
开发者ID:Alister742,项目名称:ParseKit,代码行数:56,代码来源:CookieContainer.cs

示例9: CookieCutter

        internal CookieCollection CookieCutter(Uri uri, string HeaderName, string setCookieHeader, bool isThrow) {

            CookieCollection cookies = new CookieCollection();

            CookieVariant variant = CookieVariant.Unknown;
            if (HeaderName == null) {
                variant = CookieVariant.Default;
            }
            else for (int i = 0; i < HeaderInfo.Length; ++i) {
                if ((String.Compare(HeaderName, HeaderInfo[i].Name, true, CultureInfo.InvariantCulture) == 0)) {
                        variant  = HeaderInfo[i].Variant;
                }
            }

            bool isLocalDomain = IsLocal(uri.Host);

            try {
                CookieParser parser = new CookieParser(setCookieHeader);
                do {

                    Cookie cookie = parser.Get();
                    if (cookie == null) {
//Console.WriteLine("CookieCutter: eof cookies");
                        break;
                    }

                    //Parser marks invalid cookies this way
                    if (cookie.Name == string.Empty) {
                        if(isThrow) {
                            throw new CookieException(SR.GetString(SR.net_cookie_format));
                        }
                        //Otherwise, ignore (reject) cookie
                        continue;
                    }

                    // this will set the default values from the response URI
                    // AND will check for cookie validity
                    if(!cookie.VerifySetDefaults(variant, uri, isLocalDomain, m_fqdnMyDomain, true, isThrow)) {
                        continue;
                    }
                    // If many same cookies arrive we collapse them into just one, hence setting
                    // parameter isStrict = true below
                    cookies.InternalAdd(cookie, true);

                } while (true);
            }
            catch (Exception e) {
                if(isThrow) {
                    throw new CookieException(SR.GetString(SR.net_cookie_parse_header, uri.AbsoluteUri), e);
                }
            }

            foreach (Cookie c in cookies) {
                Add(c, isThrow);
            }

            return cookies;
        }
开发者ID:ArildF,项目名称:masters,代码行数:58,代码来源:cookiecontainer.cs


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