Esempio n. 1
0
        public static RequestResult <dynamic> PostCallApi <T>(string address, T t)
        {
            var result = WebApiVisitor.PostAccessApi <T, string>(address, t);

            if (result.Result == ResultStatus.Success)
            {
                return(result);
            }
            else
            {
                throw new Exception(result.Message);
            }
        }
Esempio n. 2
0
        public static RequestResult <T> GetCallApi <T>(string address)
        {
            var result = WebApiVisitor.GetAccessApi <T>(address);

            if (result.Result == ResultStatus.Success)
            {
                return(result);
            }
            else
            {
                throw new Exception(result.Message);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// POST方式访问WebApi
        /// </summary>
        /// <typeparam name="T_Request">参数类型</typeparam>
        /// <typeparam name="T_Result">返回类型</typeparam>
        /// <param name="address">URL</param>
        /// <param name="parameter">参数</param>
        /// <returns><![CDATA[RequestResult<T_Result>]]></returns>
        public RequestResult <dynamic> PostAccessApi <T_Request, T_Result>(string address, T_Request parameter)
        {
            RequestResult <dynamic> obj = null;

            try
            {
                obj = WebApiVisitor.PostAccessApi <T_Request, T_Result>(address, parameter);
            }
            catch (Exception)
            {
                obj = new RequestResult <dynamic>()
                {
                    Result  = ResultStatus.Exception,
                    Data    = default(T_Result),
                    Message = "WebApi访问失败"
                };
            }
            return(obj);
        }
Esempio n. 4
0
        /// <summary>
        /// GET方式访问WebApi
        /// </summary>
        /// <typeparam name="T">返回类型</typeparam>
        /// <param name="address">URL</param>
        /// <returns><![CDATA[RequestResult<T>]]></returns>
        public RequestResult <T> GetAccessApi <T>(string address)
        {
            RequestResult <T> obj = null;

            try
            {
                obj = WebApiVisitor.GetAccessApi <T>(address);
            }
            catch (Exception)
            {
                obj = new RequestResult <T>()
                {
                    Result  = ResultStatus.Exception,
                    Data    = default(T),
                    Message = "WebApi访问失败"
                };
            }
            return(obj);
        }