реально проблема :( не знаю, может где то это и настраивается, но больше похоже на ошибку
посему приходится самому вручную обрабатывать куки
| Код | static CookieCollection ParseCookies(string cookies) { Cookie c = new Cookie(); CookieCollection cc = new CookieCollection(); string[] stdnames = { "expires", "domain", "path", "secure", "httponly", "version" };
Match m = Regex.Match(cookies, @"(?<name>\w+?) \s* (=\s*(?<value>(?<value1>expires)?|.*?)(;|(?(<value1>)|,)|$)|\s*$)", RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
bool first = true; while (m.Success) { string name = m.Groups["name"].Value, value = m.Groups["value"].Value;
bool std = false; foreach (string s in stdnames) if (name.ToLower() == s) { std = true; break; }
if (!std) { if (!first) {//means that a new cookie started cc.Add(c); c = new Cookie(); }
first = false; c.Name = name; c.Value = value; } else if (name == stdnames[0])//expires { Match em = Regex.Match(value, @"(?<day>Sun|Mon|Tue|Wed|Thu|Fri|Sat) (?<dayinmonth>\d\d)-(?<month>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(?<year>\d\d\d\d)(?<hour>\d\d):(?<minute>\d\d):(?<second>\d\d)", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture); if (em.Success) { string[] monthsAbbr = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" };
bool ok = true; int pos = -1; foreach (string s in monthsAbbr) if (++pos > 0 && s == em.Groups["month"].Value.ToLower()) break; ok |= pos >= 0 && pos < monthsAbbr.Length;
if (ok) { DateTime expires = new DateTime(int.Parse(em.Groups["year"].Value), pos + 1, int.Parse(em.Groups["dayinmonth"].Value), int.Parse(em.Groups["hour"].Value), int.Parse(em.Groups["minute"].Value), int.Parse(em.Groups["second"].Value), DateTimeKind.Utc).ToLocalTime(); c.Expires = expires; } } else { }//hmm, wrong expires format, omitting } else if (name == stdnames[1])//domain { c.Domain = value.Trim(); } else if (name == stdnames[2])//path { c.Path = value.Trim(); } else if (name == stdnames[3])//secure { c.Secure = true; } else if (name == stdnames[4])//httponly { c.HttpOnly = true; } else if (name == stdnames[5])//version { int version; if (int.TryParse(value, out version)) c.Version = version; } else//hmm, don't know such name, omitting it { } m = m.NextMatch(); } if (!string.IsNullOrEmpty(c.Name)) cc.Add(c); return cc; }
|
так нормально разбирает, но посмотрите пожалуйста, может где чего пропустил или напутал |