コード例 #1
0
        void SetCookies(List <KeyValuePair <string, string> > cookies)
        {
            //Remove any existing Cookie header
            IEnumerable <string> existing;

            if (headers.TryGetValues("Cookie", out existing))
            {
                headers.Remove("Cookie");
            }

            //Build cookie string
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < cookies.Count; i++)
            {
                CheckCharacters(cookies[i].Key, true);
                CheckCharacters(cookies[i].Value, false);

                sb.Append(cookies[i].Key);
                sb.Append('=');
                sb.Append(cookies[i].Value);
                if (i != cookies.Count - 1)
                {
                    sb.Append("; ");
                }
            }

            headers.Add("Cookie", sb.ToString());
        }