예제 #1
0
        /// <summary>
        /// 通过Post请求获取指定泛型返回值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="httpClientRequest"></param>
        /// <returns></returns>
        public async Task <HttpClientResponse <T> > PostAsync <T>(HttpClientRequest httpClientRequest) where T : class
        {
            HttpClientResponse <T> httpClientResponse;

            try
            {
                var httpResponseMessage = await PostAsync(httpClientRequest);

                if (httpResponseMessage == null)
                {
                    return(null);
                }

                if (!httpResponseMessage.IsSuccessStatusCode)
                {
                    httpClientResponse = new HttpClientResponse <T>
                    {
                        IsSuccess = httpResponseMessage.IsSuccessStatusCode,
                        Code      = httpResponseMessage.StatusCode
                    };

                    return(httpClientResponse);
                }

                httpClientResponse = new HttpClientResponse <T>
                {
                    IsSuccess = httpResponseMessage.IsSuccessStatusCode,
                    Code      = httpResponseMessage.StatusCode,
                    Data      = (await httpResponseMessage.Content.ReadAsStringAsync()).FromJsonString <T>()
                };
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(httpClientResponse);
        }