예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }