예제 #1
0
        /// <summary>
        /// GET 操作
        /// </summary>
        /// <typeparam name="TResult">返回对象</typeparam>
        /// <param name="requestUri">方法</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        internal async Task <TResult> Post <TResult>(string requestUri, IYingYanParam param = null)
            where TResult : CommonResult, new()
        {
            var args = GetDefaultArgs();

            if (param != null)
            {
                args = param.FillArgs(args);
            }

            CalcSn(requestUri, args, true);

            var content = new FormUrlEncodedContent(args);

            var response = await _client.PostAsync(requestUri, content);

            if (response.IsSuccessStatusCode)
            {
                return(await response.Content.JsonReadAsAsync <TResult>());
            }
            var r = new TResult();

            r.Status  = StatusCodeEnums.error999;
            r.Message = $"http 请求错误:StatusCode={response.StatusCode}, ReasonPhrase={response.ReasonPhrase}";
            return(r);
        }
예제 #2
0
        /// <summary>
        /// GET 操作
        /// </summary>
        /// <typeparam name="TResult">返回对象</typeparam>
        /// <param name="requestUri">方法</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        internal async Task <TResult> Get <TResult>(string requestUri, IYingYanParam param = null)
            where TResult : CommonResult, new()
        {
            var args = GetDefaultArgs();

            if (param != null)
            {
                args = param.FillArgs(args);
            }

            CalcSn(requestUri, args);

            if (args?.Count > 0)
            {
                var q = args.ToUriQuery();
                if (string.IsNullOrEmpty(requestUri))
                {
                    requestUri = "?" + q;
                }
                else if (requestUri.IndexOf('?') >= 0)
                {
                    requestUri += "&" + q;
                }
                else
                {
                    requestUri += "?" + q;
                }
            }

            var response = await _client.GetAsync(requestUri);

            if (response.IsSuccessStatusCode)
            {
                return(await response.Content.JsonReadAsAsync <TResult>());
            }

            var r = new TResult();

            r.Status  = StatusCodeEnums.error999;
            r.Message = $"http 请求错误:StatusCode={response.StatusCode}, ReasonPhrase={response.ReasonPhrase}";
            return(r);
        }