public static List <CookieObj> GetCookieList(string sInput, List <CookieObj> listInput) { List <string> list = CRegex.GetList(CRegex.Replace(CRegex.GetText(sInput, @"Set-Cookie:(?<Cookie>[\s\S]+?)\n", "Cookie"), "expires=([^;]+)GMT;", "", 0).Replace("path=/", ""), @"(?<cookie>[\w\d\&\.=]+[\w\d\._-]+);", "cookie"); CookieObj item = null; List <CookieObj> list2 = new List <CookieObj>(); foreach (string str4 in list) { if (str4.IndexOf('=') >= 1) { string str2 = str4.Substring(0, str4.IndexOf('=')); if (str2 != "domain") { string str3; if (str4.Length < (str4.IndexOf('=') + 1)) { str3 = ""; } else { str3 = str4.Substring(str4.IndexOf('=') + 1); } item = new CookieObj { cookieName = str2, cookieValue = str3 }; list2.Add(item); } } } foreach (CookieObj obj4 in list2) { bool flag = false; for (int i = 0; i < listInput.Count; i++) { CookieObj obj3 = listInput[i]; if (obj3.cookieName == obj4.cookieName) { flag = true; obj3.cookieValue = obj4.cookieValue; } } if (!flag) { listInput.Add(obj4); } } return(listInput); }
public static void SetCookie(List <CookieObj> listInput, string CookieName, string CookieValue) { foreach (CookieObj obj2 in listInput) { if (obj2.cookieName == CookieName) { obj2.cookieValue = CookieValue; return; } } CookieObj item = new CookieObj { cookieName = CookieName, cookieValue = CookieValue }; listInput.Add(item); }