コード例 #1
0
        /// <summary>
        /// 统一的方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="func"></param>
        /// <returns></returns>
        public JSONResult <T> UnifiedFucn <T>(Func <JSONResult <T> > func)
        {
            var model = new JSONResult <T>();

            try
            {
                var RetFunc = func();
                return(RetFunc);
            }
            catch (Exception ex)
            {
                model.Result  = "读取失败:" + ex.Message;
                model.ret     = 3;
                model.Success = false;
            }
            return(model);
        }
コード例 #2
0
        /// <summary>
        /// 统一的POST方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="func"></param>
        /// <returns></returns>
        public JSONResult <T> UnifiedFucnPost <T>(string BaseURL, Dictionary <string, string> parseData
                                                  , out System.Net.HttpStatusCode StatusCode, string CookieName = "")
        {
            var model     = new JSONResult <T>();
            var msgresult = "";
            var errmsg    = "";
            var code      = new System.Net.HttpStatusCode();

            try
            {
                if (CookieName == "")
                {
                    CookieName = BaseGlobalParameter.defUinfoCookie;
                }
                var isSucceed = HttpGetPostHepler.Post(BaseURL, parseData, out msgresult, out errmsg, out code, CookieName);
                if (isSucceed == true)
                {
                    var res = Newtonsoft.Json.JsonConvert.DeserializeObject
                              <JSONResult <T> >(msgresult);
                    StatusCode = code;
                    return(res);
                }
            }
            catch (Exception ex)
            {
                if (errmsg != "")
                {
                    model.Result = ex.Message;
                }
                else
                {
                    model.Result = "读取失败:" + ex.Message;
                }
                model.ret     = 4;
                model.Success = false;
            }
            StatusCode    = code;
            model.Result  = errmsg;
            model.Success = false;
            model.ret     = 3;
            return(model);
        }