/// <summary> /// 实体转成Delete参数 /// </summary> /// <typeparam name="T">请求参数实体类型</typeparam> /// <typeparam name="K">返回结果实体类型</typeparam> /// <param name="url">请求url</param> /// <param name="param">请求参数实体</param> /// <returns></returns> public async Task <K> Delete <T, K>(string url, T param) { HttpClient httpClient = new HttpClient(); //httpClient.DefaultRequestHeaders.Add("Accept", "application/json"); var paramStr = ModelToHttpParam <T> .ToGetParam(param); var requstResult = await httpClient.DeleteAsync(url + paramStr); var result = string.Empty; using (requstResult) { result = await requstResult.Content.ReadAsStringAsync(); } return(JsonConvert.DeserializeObject <K>(result)); }
/// <summary> /// 实体转成get参数 /// </summary> /// <typeparam name="T">请求参数实体类型</typeparam> /// <typeparam name="K">返回结果实体类型</typeparam> /// <param name="url">请求url</param> /// <param name="param">请求参数实体</param> /// <returns></returns> public async Task <K> Get <T, K>(string url, T param) { HttpClient httpClient = new HttpClient(); //httpClient.DefaultRequestHeaders.Add("Accept", "application/json"); //httpClient.DefaultRequestHeaders.Add("sToken", "sToken:ad38ee1ee36dc44cc12a08d85992a3f9"); //httpClient.DefaultRequestHeaders.Add("sOrgId", "749f3b9bc97acfbca91308d8597f0a50"); var paramStr = ModelToHttpParam <T> .ToGetParam(param); var requstResult = await httpClient.GetAsync(url + paramStr); var result = string.Empty; using (requstResult) { result = await requstResult.Content.ReadAsStringAsync(); } return(JsonConvert.DeserializeObject <K>(result)); }
/// <summary> /// Post请求 /// </summary> /// <typeparam name="T">请求参数实体类型</typeparam> /// <typeparam name="K">返回结果实体类型</typeparam> /// <param name="url">请求url</param> /// <param name="param">请求参数实体</param> /// <returns></returns> public async Task <K> Post <T, K>(string url, T param) { HttpClient httpClient = new HttpClient(); var paramStr = ModelToHttpParam <T> .ToPostParam(param); var strContent = new StringContent(paramStr); strContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");// ("content-type", "application/json"); httpClient.DefaultRequestHeaders.Add("sToken", "sToken:3a044cc0c61fcdfa14c608d8617dc4ea"); httpClient.DefaultRequestHeaders.Add("sOrgId", "bc4171c2e46ecf7d556808d8607877a5"); var requstResult = await httpClient.PostAsync(url, strContent); var result = string.Empty; using (requstResult) { result = await requstResult.Content.ReadAsStringAsync(); } return(JsonConvert.DeserializeObject <K>(result)); }