Example #1
0
        // _perform_auth_request
        private async Task <Dictionary <string, string> > PerformAuthRequest(Dictionary <string, string> data)
        {
            var nvc = new List <KeyValuePair <string, string> >();

            foreach (var kvp in data)
            {
                nvc.Add(new KeyValuePair <string, string>(kvp.Key.ToString(), kvp.Value.ToString()));
            }

            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
            {
                client.DefaultRequestHeaders.Add("User-Agent", userAgent);
                string result;
                try
                {
                    var response = await client.PostAsync(authUrl, new FormUrlEncodedContent(nvc));

                    result = await response.Content.ReadAsStringAsync();
                }
                catch (Exception e)
                {
                    result = e.Message;
                }

                return(GoogleKeyUtils.ParseAuthResponse(result));
            }
        }
Example #2
0
        // _perform_auth_request
        private Dictionary <string, string> PerformAuthRequest(Dictionary <string, string> data)
        {
            NameValueCollection nvc = new NameValueCollection();

            foreach (var kvp in data)
            {
                nvc.Add(kvp.Key.ToString(), kvp.Value.ToString());
            }
            using (WebClient client = new WebClient()
            {
                Proxy = Proxy
            })
            {
                client.Headers.Add(HttpRequestHeader.UserAgent, userAgent);
                string result;
                try
                {
                    byte[] response = client.UploadValues(authUrl, nvc);
                    result = Encoding.UTF8.GetString(response);
                }
                catch (WebException e)
                {
                    result = new StreamReader(e.Response.GetResponseStream()).ReadToEnd();
                }
                return(GoogleKeyUtils.ParseAuthResponse(result));
            }
        }
Example #3
0
        // _perform_auth_request
        private Dictionary <string, string> PerformAuthRequest(Dictionary <string, string> data)
        {
            var nvc = new NameValueCollection();

            if (data == null)
            {
                return new Dictionary <string, string> {
                           { "Error", "Data looks like null, are u sure u used Application specific password?" }
                }
            }
            ;
            foreach (var kvp in data)
            {
                nvc.Add(kvp.Key, kvp.Value);
            }
            using (var client = new WebClient()
            {
                Proxy = _proxy
            })
            {
                client.Headers.Add(HttpRequestHeader.UserAgent, UserAgent);
                var result = "";
                try
                {
                    var response = client.UploadValues(AuthUrl, nvc);
                    result = Encoding.UTF8.GetString(response);
                }
                catch (WebException e)
                {
                    var resp = e.Response?.GetResponseStream();
                    if (resp != null)
                    {
                        result = new StreamReader(resp).ReadToEnd();
                    }
                }
                return(GoogleKeyUtils.ParseAuthResponse(result));
            }
        }
Example #4
0
        // _perform_auth_request
        private async Task <Dictionary <string, string> > PerformAuthRequest(Dictionary <string, string> data)
        {
            var nvc = new List <KeyValuePair <string, string> >();

            foreach (var kvp in data)
            {
                nvc.Add(new KeyValuePair <string, string>(kvp.Key, kvp.Value));
            }

            string result;

            try
            {
                var response = await HttpClient.PostAsync(_authUrl, new FormUrlEncodedContent(nvc));

                result = await response.Content.ReadAsStringAsync();
            }
            catch (Exception e)
            {
                result = e.Message;
            }

            return(GoogleKeyUtils.ParseAuthResponse(result));
        }