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));
                }
            }
        }
 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;
 }
Пример #3
0
        private void CheckForErrors(CodeScales.Http.Methods.HttpResponse response)
        {
            var status = EntityUtils.ToString(response.Entity);
            var stream = new MemoryStream(Encoding.UTF8.GetBytes(status));

            using (var reader = XmlReader.Create(stream))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name)
                        {
                            case "result":
                                break;
                            case "message": // success
                                return;
                            case "error": // failure
                                throw new ProtocolViolationException(status);
                            default:
                                throw new ArgumentException("Unknown element: " + reader.Name);
                        }
                    }
                }
            }
        }