Exemplo n.º 1
0
        public async Task <HttpResponseResult> Delete(string url)
        {
            HttpResponseResult result = null;

            using (var http = this.InitHttp())
            {
                var response = await http.DeleteAsync(url);

                result = response.ConvertToResult();
            }
            return(result);
        }
Exemplo n.º 2
0
        public async Task <HttpResponseResult> Get(string url, object param)
        {
            url = this.GetUrl(url, param);
            HttpResponseResult result = null;

            using (var http = this.InitHttp())
            {
                var response = await http.GetAsync(url);

                result = response.ConvertToResult();
            }
            return(result);
        }
Exemplo n.º 3
0
        public async Task <HttpResponseResult> Put(string url, string json)
        {
            HttpResponseResult result = null;

            using (var http = this.InitHttp())
            {
                HttpContent content  = new StringContent(json, Encoding.UTF8, "application/json");
                var         response = await http.PutAsync(url, content);

                result = response.ConvertToResult();
            }
            return(result);
        }
Exemplo n.º 4
0
        public static HttpResponseResult ConvertToResult(this HttpResponseMessage response)
        {
            HttpResponseResult result;

            try
            {
                response.EnsureSuccessStatusCode();
                result = Task.Run(async() => await response.Content.ReadAsStringAsync()).ContinueWith(m => new HttpResponseResult(m.Result, HttpStatusCode.OK)).Result;
            }
            catch (HttpRequestException ex)
            {
                result = new HttpResponseResult(ex.Message, HttpStatusCode.InternalServerError);
            }
            return(result);
        }
Exemplo n.º 5
0
        public async Task <HttpResponseResult> Post <T>(string url, T data)
        {
            HttpResponseResult result = null;

            if (data == null)
            {
                result = null;
            }

            using (var http = this.InitHttp())
            {
                string      json     = data.ToJson <T>();
                HttpContent content  = new StringContent(json, Encoding.UTF8, "application/json");
                var         response = await http.PostAsync(url, content);

                result = response.ConvertToResult();
            }

            return(result);
        }