//get请求 public static TResult Get<TResult>(string host, string url) { var httpClient = new HttpClient { BaseAddress = new Uri(host), }; var resp = httpClient.GetAsync(url).Result; resp.EnsureSuccessStatusCode(); var result = resp.Content.ReadAsAsync<TResult>().Result; return result; } //post请求 public static TResult Post<TParam, TResult>(string host, string url, TParam param) { var httpClient = new HttpClient { BaseAddress = new Uri(host), }; HttpContent contentPost = new StringContent(JsonConvert.SerializeObject(param), Encoding.UTF8, "application/json"); var resp = httpClient.PostAsync(url, contentPost).Result; resp.EnsureSuccessStatusCode(); var result = resp.Content.ReadAsAsync<TResult>().Result; return result; }