public static void AddHttpCookie(string headerPart, CodeScales.Http.Cookies.HttpCookieCollection cookies) { if (headerPart == null || headerPart == "" || cookies == null) { return; } string[] cookie_components = headerPart.Split(';'); if (cookie_components != null && cookie_components.Length > 0) { string kv = cookie_components[0]; int pos = kv.IndexOf('='); if (pos == -1) { /* XXX ugh */ } else { string key = kv.Substring(0, pos).Trim(); string val = kv.Substring(pos + 1).Trim(); cookies.Add(key, new CodeScales.Http.Cookies.HttpCookie(key, val)); } } }
internal void ReadCookiesFromResponse(HttpResponse response) { lock (this) { Uri responseUri = response.RequestUri; HttpCookieCollection cookieColl = null; if (this.m_cookieStore.ContainsKey(responseUri.Host)) { cookieColl = this.m_cookieStore[responseUri.Host]; } else { cookieColl = new HttpCookieCollection(); this.m_cookieStore.Add(responseUri.Host, cookieColl); } string [] cookieHeaders = response.Headers.GetValues("Set-Cookie"); if (cookieHeaders != null) { foreach (string header in cookieHeaders) { HTTPProtocol.AddHttpCookie(header, cookieColl); } } } }
public static string GetCookiesHeader(CodeScales.Http.Cookies.HttpCookieCollection cookies) { if (cookies != null && cookies.Count > 0) { int cookieCounter = 0; StringBuilder sb = new StringBuilder(); // sb.Append("Cookie: "); foreach (string key in cookies.Keys) { sb.Append(key + "=" + cookies.GetCookie(key).Value); if (cookieCounter < cookies.Count - 1) { sb.Append(';'); } cookieCounter++; } return(sb.ToString()); // +"\r\n"; } return(null); }