public async Task <HttpData <string> > PostAsync <T>(Uri requestUri, T value) { HttpData <string> result = null; string data = string.Empty; HttpResponseMessage response = null; try { /// Prepare JSON content string body = Common.PrepareJsonBody(value); HttpContent content = new StringContent(body, System.Text.Encoding.UTF8, Common.JsonContentType); OnRequestExecute(new ExecutionInfoEventArgs(requestUri, HttpVerb.Post, body, _client.DefaultRequestHeaders, content.Headers)); // Option 1 - Make simple request response = await _client.PostAsync(requestUri, content); // Option 2 - Make request with custom headers //var request = new HttpRequestMessage //{ // RequestUri = requestUri, // Method = HttpMethod.Post, // Content = content //}; //response = await _client.SendAsync(request); data = await response.Content.ReadAsStringAsync(); result = new HttpData <string>(response, data); // throws an exception if the status code falls outside the range 200–299 response.EnsureSuccessStatusCode(); } catch (Exception ex) { ManageException(ex, requestUri, result, HttpVerb.Post); } return(result); }
public HttpData(HttpData <string> data, T content) : base(data) { this.Content = content; }