Beispiel #1
0
        /// <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));
        }
Beispiel #2
0
        /// <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));
        }