using SinochemCloudClient.Models; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; namespace SinochemCloudClient { public class CloudCommunicator where TRequest : RequestBase where TResponse : ResponseBase { private HttpClient client; private string url; public CloudCommunicator(string apiUrl) { client = new HttpClient(); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); this.url = apiUrl; } public void SendRequest(TRequest request) { try { HttpResponseMessage httpResponse = client.PostAsJsonAsync(url, request).Result; httpResponse.EnsureSuccessStatusCode(); Response = httpResponse.Content.ReadAsAsync().Result; } catch (Exception ex) { Response = null; Console.WriteLine(ex); } } public TResponse Response { get; private set; } } }