コード例 #1
0
        public static async Task <T> GetConnectHelperAsync <T>(string url)
        {
            WebApiService_Helper api = new WebApiService_Helper();

            using (HttpClient client = api.GetClient())
            {
                try
                {
                    HttpResponseMessage response = await client.GetAsync(HttpBaseAddress + url);

                    if (!response.IsSuccessStatusCode)
                    {
                        var error = await response.Content.ReadAsAsync <TrackSeriesApiError>();

                        var message = error != null ? error.Message : "";
                        throw new TrackSeriesApiException(message, response.StatusCode);
                    }
                    string resultStr = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <T>(resultStr));
                }
                catch (HttpRequestException ex)
                {
                    throw new TrackSeriesApiException("", false, ex);
                }
                catch (UnsupportedMediaTypeException ex)
                {
                    throw new TrackSeriesApiException("", false, ex);
                }
                catch (Exception ex)
                {
                    return(default(T));
                }
            }
        }
コード例 #2
0
        public static async Task <HttpStatusCode> DeleteConnectHelperAsync(string url)
        {
            WebApiService_Helper api = new WebApiService_Helper();

            using (HttpClient client = api.GetClient())
            {
                try
                {
                    HttpResponseMessage response = await client.DeleteAsync(
                        url);

                    return(response.StatusCode);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
コード例 #3
0
        public static async Task <Uri> CreateConnectHelperAsync <T>(string url, T cls)
        {
            WebApiService_Helper api = new WebApiService_Helper();

            using (HttpClient client = api.GetClient())
            {
                try
                {
                    HttpResponseMessage response = await client.PostAsJsonAsync <T>(
                        url, cls);

                    response.EnsureSuccessStatusCode();

                    return(response.Headers.Location);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
コード例 #4
0
        public static async Task <T> UpdateConnectHelperAsync <T>(string url, T cls)
        {
            WebApiService_Helper api = new WebApiService_Helper();

            using (HttpClient client = api.GetClient())
            {
                try
                {
                    HttpResponseMessage response = await client.PutAsJsonAsync(
                        url, cls);

                    response.EnsureSuccessStatusCode();

                    return(await response.Content.ReadAsAsync <T>());
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }