Beispiel #1
0
        //https://wiki.apache.org/couchdb/Session_API
        // DELETE api/_sevalues/5
        public logout_response Delete()
        {
            try
            {
                string request_string = Program.config_couchdb_url + "/_session";


                System.Net.WebRequest request = System.Net.WebRequest.Create(new Uri(request_string));
                request.Method          = "DELETE";
                request.PreAuthenticate = false;

                if (!string.IsNullOrWhiteSpace(this.Request.Cookies["AuthSession"]))
                {
                    string auth_session_value = this.Request.Cookies["AuthSession"];
                    request.Headers.Add("Cookie", "AuthSession=" + auth_session_value);
                    request.Headers.Add("X-CouchDB-WWW-Authenticate", auth_session_value);
                }



                System.Net.WebResponse response    = (System.Net.HttpWebResponse)request.GetResponse();
                System.IO.Stream       dataStream  = response.GetResponseStream();
                System.IO.StreamReader reader      = new System.IO.StreamReader(dataStream);
                string          responseFromServer = reader.ReadToEnd();
                logout_response json_result        = Newtonsoft.Json.JsonConvert.DeserializeObject <logout_response>(responseFromServer);

                return(json_result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(null);
        }
Beispiel #2
0
        //https://wiki.apache.org/couchdb/Session_API
        // DELETE api/_sevalues/5
        public async System.Threading.Tasks.Task <logout_response> Delete()
        {
            try
            {
                string request_string         = Program.config_couchdb_url + "/_session";
                System.Net.WebRequest request = System.Net.WebRequest.Create(new Uri(request_string));
                request.Method          = "DELETE";
                request.PreAuthenticate = false;

                if (this.Request.Headers.Contains("Cookie") && this.Request.Headers.GetValues("Cookie").Count() > 0)
                {
                    string[] cookie_set = this.Request.Headers.GetValues("Cookie").First().Split(';');
                    for (int i = 0; i < cookie_set.Length; i++)
                    {
                        string[] auth_session_token = cookie_set[i].Split('=');
                        if (auth_session_token[0].Trim() == "AuthSession")
                        {
                            request.Headers.Add("Cookie", "AuthSession=" + auth_session_token[1]);
                            request.Headers.Add("X-CouchDB-WWW-Authenticate", auth_session_token[1]);
                            break;
                        }
                    }
                }


                System.Net.WebResponse response = await request.GetResponseAsync();

                System.IO.Stream       dataStream  = response.GetResponseStream();
                System.IO.StreamReader reader      = new System.IO.StreamReader(dataStream);
                string          responseFromServer = reader.ReadToEnd();
                logout_response json_result        = Newtonsoft.Json.JsonConvert.DeserializeObject <logout_response>(responseFromServer);

                return(json_result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(null);
        }