Ejemplo n.º 1
0
        protected async Task <T> PostJsonAsync <T>(string requestUri, string json)
        {
            HttpResponseMessage response;
            string responseContent = null;

            var content = new StringContent(json, Encoding.UTF8, "application/json");

            try
            {
                response = await client.PostAsync(requestUri, content).ConfigureAwait(false);

                responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                response.EnsureSuccessStatusCode();
            }
            catch (HttpRequestException)
            {
                RippleRestErrorResponse r;

                if (RippleRestErrorResponse.TryParse(responseContent, out r))
                {
                    throw new RippleRestErrorException(r);
                }
                else
                {
                    throw;
                }
            }

            return(JsonConvert.DeserializeObject <T>(responseContent, serializerSettings));
        }
Ejemplo n.º 2
0
        protected async Task <T> GetJsonAsync <T>(string requestUri)
        {
            HttpResponseMessage response = null;
            string responseContent       = null;

            try
            {
                response = await client.GetAsync(requestUri).ConfigureAwait(false);

                responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                response.EnsureSuccessStatusCode();
            }
            catch (HttpRequestException)
            {
                RippleRestErrorResponse r;

                if (RippleRestErrorResponse.TryParse(responseContent, out r))
                {
                    throw new RippleRestErrorException(r);
                }
                else
                {
                    throw;
                }
            }

            return(JsonConvert.DeserializeObject <T>(responseContent, serializerSettings));
        }