Exemplo n.º 1
0
        public async Task <TResponse> PostRequestAsync <TResponse, T>(RequestUri requestUri, T value, CancellationToken cancellationToken)
        {
            try
            {
                var uri      = new Uri(Hosts.GetRestUri(), requestUri.ToString());
                var response = await Client.PostAsJsonAsync(uri, value, cancellationToken).ConfigureAwait(false);

                response.EnsureSuccessStatusCode();

                var formatters = new List <MediaTypeFormatter>
                {
                    new DefaultJsonMediaTypeFormatter(Settings)
                };

                return(await response.Content.ReadAsAsync <TResponse>(formatters, cancellationToken).ConfigureAwait(false));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                throw;
            }
        }
Exemplo n.º 2
0
 public async Task PostRequestAsync <T>(RequestUri requestUri, T value, CancellationToken cancellationToken)
 => await PostRequestAsync <HttpResponseMessage, T>(requestUri, value, cancellationToken).ConfigureAwait(false);