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); }
public static string GetCookieByHead(string sInput) { string strCookie = CRegex.GetText(sInput, @"Set-Cookie:(?<Cookie>[\s\S]+?)\n", "Cookie"); List <string> list = CRegex.GetList(strCookie, @"(?<cookie>[\w\d\.]+=[\w\d\._-]+);", "cookie"); string sReturnCookie = ""; foreach (string s in list) { sReturnCookie += s + "; "; } return(sReturnCookie); }