Ejemplo n.º 1
0
        private async Task <string> SendRequest(HttpMethod method, string requestPath, HttpContent httpContent)
        {
            try
            {
                HttpResponseMessage msg = null;
                var log = string.Empty;
                if (method == HttpMethod.Get)
                {
                    requestPath += "?";
                    var data = await httpContent.ReadAsStringAsync();

                    requestPath += data;
                    msg          = await _httpClient.GetAsync(requestPath);
                }
                else if (method == HttpMethod.Post)
                {
                    msg = await _httpClient.PostAsync(requestPath, httpContent);

                    log = await msg.Content.ReadAsStringAsync();
                }
                else if (method == HttpMethod.Put)
                {
                    msg = await _httpClient.PutAsync(requestPath, httpContent);

                    log = await msg.Content.ReadAsStringAsync();
                }
                if (msg == null)
                {
                    throw new Exception("Invalid Method");
                }
                else if (msg.StatusCode != HttpStatusCode.OK)
                {
                    throw new Exception(msg.ReasonPhrase + " " + log);
                }
                else
                {
                    var data = await msg.Content.ReadAsStringAsync();

                    return(data);
                }
            }
            catch (Exception e)
            {
                LogEngine.Error(e);
                return(string.Empty);
            }
        }
Ejemplo n.º 2
0
        public static async Task <IDictionary <string, string> > GetPair(object data)
        {
            if (data == null)
            {
                return(new Dictionary <string, string>());
            }

            try
            {
                return(await Task.Run(() => ToKeyValue(data)));
            }
            catch (Exception ex)
            {
                LogEngine.Error(ex);
                return(new Dictionary <string, string>());
            }
        }