Exemplo n.º 1
0
        protected async Task <RestResult> GetAsync(string method)
        {
            RestResult result = new RestResult();

            try {
                string uri      = url + method;
                var    response = await client.GetAsync(uri);

                result.RestResponse = await response.Content.ReadAsStringAsync();

                if (!response.IsSuccessStatusCode)
                {
                    result.statusCode   = ((int)response.StatusCode);
                    result.status       = response.ReasonPhrase;
                    result.RestResponse = "";
                }
            } catch (Exception ex) {
                result.statusCode = 1;
                result.status     = ex.Message;
            }
            return(result);
        }
Exemplo n.º 2
0
        protected async Task <RestResult> ExecuteAsync(string postData, string method)
        {
            RestResult result = new RestResult();

            try {
                HttpContent content  = new System.Net.Http.StringContent(postData, System.Text.Encoding.UTF8, "application/json");
                string      uri      = url + method;
                var         response = await client.PostAsync(uri, content);

                result.RestResponse = await response.Content.ReadAsStringAsync();

                if (!response.IsSuccessStatusCode)
                {
                    result.statusCode   = ((int)response.StatusCode);
                    result.status       = response.ReasonPhrase;
                    result.RestResponse = "";
                }
            } catch (Exception ex) {
                result.statusCode = 1;
                result.status     = ex.Message;
            }
            return(result);
        }