Exemplo n.º 1
0
        public async Task <string> PostLogout(string url, string sessionId, string serverName)
        {
            var content = new StringContent("{}", Encoding.UTF8, "application/json");

            using (var handler = NtlmHttpHandlerFactory.Create())
            {
                AddSession(handler, sessionId, serverName);
                using (var comosHttpClient = new ComosHttp(handler))
                {
                    Uri myCookieUri = new Uri(serverName);
                    handler.CookieContainer.Add(myCookieUri, new Cookie("XSRF-TOKEN", XsrfToken));
                    comosHttpClient.DefaultRequestHeaders.Add("X-XSRF-TOKEN", XsrfToken);
                    var response = await comosHttpClient.PostAsync(url + "sessions/actions/logout", content, TokenSource.Token).ConfigureAwait(false);

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        return(await response.Content.ReadAsStringAsync());
                    }
                    else
                    {
                        throw new Exception(response.ReasonPhrase);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private async Task <HttpResponseMessage> PostToComosWeb(string url, string serverName)
        {
            var content = new StringContent("{}", Encoding.UTF8, "application/json");

            using (var handler = NtlmHttpHandlerFactory.Create())
            {
                using (var comosHttpClient = new ComosHttp(handler))
                {
                    Uri myCookieUri = new Uri(serverName);
                    handler.CookieContainer.Add(myCookieUri, new Cookie("XSRF-TOKEN", XsrfToken));
                    comosHttpClient.DefaultRequestHeaders.Add("X-XSRF-TOKEN", XsrfToken);
                    return(await comosHttpClient.PostAsync(url, content).ConfigureAwait(false));
                }
            }
        }
Exemplo n.º 3
0
        public async Task <HttpResponseMessage> DoHeartbeat(string url, string sessionId, string serverName)
        {
            using (var handler = NtlmHttpHandlerFactory.Create())
            {
                AddSession(handler, sessionId, serverName);
                using (var comosHttpClient = new ComosHttp(handler))
                {
                    var json = JsonConvert.SerializeObject(
                        new
                    {
                        text = sessionId
                    });

                    var content     = new StringContent(json, Encoding.UTF8, "application/json");
                    Uri myCookieUri = new Uri(serverName);
                    handler.CookieContainer.Add(myCookieUri, new Cookie("XSRF-TOKEN", XsrfToken));
                    comosHttpClient.DefaultRequestHeaders.Add("X-XSRF-TOKEN", XsrfToken);
                    return(await comosHttpClient.PostAsync(url + "sessions/actions/send_heartbeat", content).ConfigureAwait(false));
                }
            }
        }