Exemplo n.º 1
0
        /// <summary>
        /// Reads cookie parameters into Dictionary.
        /// </summary>
        /// <param name="source">Incoming HttpWebResponse instance.</param>
        /// <param name="host">Host to fetch cookies for.</param>
        /// <returns>Dictionary with found header parameters.</returns>
        public static Dictionary <string, string> ReadoutCookies(this HttpWebResponse source, Uri host)
        {
            var cookieDictionary = new Dictionary <string, string>();

            if (source.Cookies.Count != 0)
            {
                foreach (Cookie cookie in source.Cookies)
                {
                    if (!cookie.Value.IsNullOrEmpty())
                    {
                        cookieDictionary.Add(cookie.Name, cookie.Value);
                    }
                }
            }
            else if (source.Headers[CookieHeaderName].IsNotNullOrEmpty())
            {
                foreach (Cookie cookie in source.FetchCookiesFromHeader(host))
                {
                    cookieDictionary.Add(cookie.Name, cookie.Value);
                }
            }

            return(cookieDictionary);
        }