Repersent a web request for CouchDB database.
Inheritance: ICouchRequest
Exemple #1
0
        public Cookie GetSession()
        {
            var authCookie = cookiestore["authcookie"];

            if (authCookie != null)
            {
                return(authCookie);
            }

            if (string.IsNullOrEmpty(username))
            {
                return(null);
            }
            var request = new CouchRequest(baseUri + "_session");

            request.GetRequest().Headers.Add("Authorization:Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password)));
            using (HttpWebResponse response = request.Post()
                                              .Form()
                                              .Data("name=" + username + "&password="******"Set-Cookie");
                if (header != null)
                {
                    var parts = header.Split(';')[0].Split('=');
                    authCookie        = new Cookie(parts[0], parts[1]);
                    authCookie.Domain = response.Server;
                    cookiestore.Add("authcookie", authCookie, TimeSpan.FromMinutes(9));
                }
                return(authCookie);
            }
        }
Exemple #2
0
        public Cookie GetSession()
        {
            var authCookie = cookiestore["authcookie"];

            if (authCookie != null)
                return authCookie;

            if (string.IsNullOrEmpty(username)) return null;
            var request = new CouchRequest(baseUri + "_session");
            request.GetRequest().Headers.Add("Authorization:Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password)));
            using (HttpWebResponse response = request.Post()
                .Form()
                .Data("name=" + username + "&password="******"Set-Cookie");
                if (header != null)
                {
                    var parts = header.Split(';')[0].Split('=');
                    authCookie = new Cookie(parts[0], parts[1]);
                    authCookie.Domain = response.Server;
                    cookiestore.Add("authcookie", authCookie, TimeSpan.FromMinutes(9));
                }
                return authCookie;
            }
        }
Exemple #3
0
        protected Cookie GetSession()
        {
            var authCookie = cookiestore["authcookie"];

            if (authCookie != null)
                return authCookie;

            if (string.IsNullOrEmpty(username)) return null;
            var request = new CouchRequest(baseUri + "_session");
            var response = request.Post()
                .ContentType("application/x-www-form-urlencoded")
                .Data("name=" + username + "&password="******"Response from authentication post yielded a null reference exception.");
            }

            var header = response.Headers.Get("Set-Cookie");
            if (header != null)
            {
                var parts = header.Split(';')[0].Split('=');
                authCookie = new Cookie(parts[0], parts[1]);
                authCookie.Domain = response.Server;
                cookiestore.Add("authcookie", authCookie, TimeSpan.FromMinutes(9));
            }
            return authCookie;
        }
Exemple #4
0
 public static bool Authenticate(string baseUri, string userName, string password)
 {
     if (!baseUri.Contains("http://"))
         baseUri = "http://" + baseUri;
     var request = new CouchRequest(baseUri + "/_session");
     var response = request.Post()
         .ContentType("application/x-www-form-urlencoded")
         .Data("name=" + userName + "&password=" + password)
         .Timeout(3000)
         .GetCouchResponse();
     return response.StatusCode == HttpStatusCode.OK;
 }
Exemple #5
0
        public static bool Authenticate(string baseUri, string userName, string password)
        {
            if (!baseUri.Contains("http://"))
            {
                baseUri = "http://" + baseUri;
            }
            var request  = new CouchRequest(baseUri + "/_session");
            var response = request.Post()
                           .ContentType("application/x-www-form-urlencoded")
                           .Data("name=" + userName + "&password=" + password)
                           .Timeout(3000)
                           .GetCouchResponse();

            return(response.StatusCode == HttpStatusCode.OK);
        }
Exemple #6
0
        protected Cookie GetSession()
        {
            if (string.IsNullOrEmpty(username)) return null;
            var request = new CouchRequest(baseUri + "_session");
            var response = request.Post()
                .ContentType("application/x-www-form-urlencoded")
                .Data("name=" + username + "&password="******"Set-Cookie");
            if (header != null)
            {
                var parts = header.Split(';')[0].Split('=');
                var authCookie = new Cookie(parts[0], parts[1]);
                authCookie.Domain = response.Server;
                return authCookie;
            }
            return null;
        }
Exemple #7
0
        protected CouchRequest GetRequest(string uri, string etag)
        {
            CouchRequest request;

            if (AuthenticationType.Cookie == this.authType)
            {
                request = new CouchRequest(uri, GetSession(), etag);
            }
            else if (AuthenticationType.Basic == this.authType) //Basic Authentication
            {
                request = new CouchRequest(uri, username, password);
            }
            else //default Cookie
            {
                request = new CouchRequest(uri, GetSession(), etag);
            }
            if (timeout.HasValue)
            {
                request.Timeout(timeout.Value);
            }
            return(request);
        }
Exemple #8
0
 protected CouchRequest GetRequest(string uri, string etag)
 {
     CouchRequest request;
     if (AuthenticationType.Cookie == this.authType)
     {
         request = new CouchRequest(uri, GetSession(), etag);
     }
     else if (AuthenticationType.Basic == this.authType) //Basic Authentication
     {
         request = new CouchRequest(uri, username, password);
     }
     else //default Cookie
     {
         request = new CouchRequest(uri, GetSession(), etag);
     }
     if (timeout.HasValue) request.Timeout(timeout.Value);
     return request;
 }
Exemple #9
0
 protected CouchRequest GetRequest(string uri, string etag)
 {
     var request = new CouchRequest(uri, GetSession(), etag);
     return request;
 }