Example #1
0
        /// <summary>
        /// http请求
        /// </summary>
        /// <typeparam name="TData"></typeparam>
        /// <param name="method"></param>
        /// <param name="apiPath"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        protected virtual async Task <TData> RequestAsync <TData>(HttpMethod method, string apiPath = null, object param = null)
        {
            using var requester = new HttpRequester(method, ApiUrl + apiPath);
            var response = await requester.GetResultAsync <TData>(param);

            if (response.Code == HttpStatusCode.OK || response.Code == HttpStatusCode.NoContent)
            {
                return(response.Data);
            }
            if (response.Code == HttpStatusCode.BadRequest)
            {
                throw new BizException(response.Message);
            }
            throw new Exception(response.Message);
        }