Example #1
0
        public static List <CookieObj> GetCookieList(string sInput, List <CookieObj> listInput)
        {
            string strCookie = CRegex.GetText(sInput, @"Set-Cookie:(?<Cookie>[\s\S]+?)\n", "Cookie");

            strCookie = CRegex.Replace(strCookie, @"expires=([^;]+)GMT;", "", 0);
            strCookie = strCookie.Replace("path=/", "");
            List <string>    list = CRegex.GetList(strCookie, @"(?<cookie>[\w\d\&\.=]+[\w\d\._-]+);", "cookie");
            string           cookieName, cookieValue;
            CookieObj        mCookie    = null;
            List <CookieObj> listCookie = new List <CookieObj>();

            foreach (string s in list)
            {
                if (s.IndexOf('=') < 1)
                {
                    continue;
                }

                cookieName = s.Substring(0, s.IndexOf('='));
                if (cookieName == "domain")
                {
                    continue;
                }
                if (s.Length < s.IndexOf('=') + 1)
                {
                    cookieValue = "";
                }
                else
                {
                    cookieValue = s.Substring(s.IndexOf('=') + 1);
                }
                mCookie             = new CookieObj();
                mCookie.cookieName  = cookieName;
                mCookie.cookieValue = cookieValue;
                listCookie.Add(mCookie);
            }
            bool      blExists;
            CookieObj mInput;

            foreach (CookieObj model in listCookie)
            {
                blExists = false;
                for (int i = 0; i < listInput.Count; i++)
                {
                    mInput = listInput[i];
                    if (mInput.cookieName == model.cookieName)
                    {
                        blExists           = true;
                        mInput.cookieValue = model.cookieValue;
                    }
                }
                if (!blExists)
                {
                    listInput.Add(model);
                }
            }
            return(listInput);
        }
Example #2
0
        public static void SetCookie(List <CookieObj> listInput, string CookieName, string CookieValue)
        {
            foreach (CookieObj mCookie in listInput)
            {
                if (mCookie.cookieName == CookieName)
                {
                    mCookie.cookieValue = CookieValue;
                    return;
                }
            }
            CookieObj obj = new CookieObj();

            obj.cookieName  = CookieName;
            obj.cookieValue = CookieValue;
            listInput.Add(obj);
        }