示例#1
0
文件: Post.cs 项目: au-x/Cissy.Core
        /// <summary>
        /// 获取Post结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="returnText"></param>
        /// <returns></returns>
        public static T GetResult <T>(string returnText) where T : IModel
        {
            if (returnText.Contains("errcode"))
            {
                //可能发生错误
                WxJsonResult errorResult = returnText.GetObject <WxJsonResult>();
                if (errorResult.errcode != ReturnCode.请求成功)
                {
                    //发生错误
                    throw new Exception(errorResult.errmsg);
                    //throw new ApplicationException(
                    //    string.Format("微信Post请求发生错误!错误代码:{0},说明:{1}",
                    //                  (int)errorResult.errcode,
                    //                  errorResult.errmsg));
                }
            }

            T result = returnText.JsonToModel <T>();

            return(result);
        }
示例#2
0
        /// <summary>
        /// GET方式请求URL,并返回T类型
        /// </summary>
        /// <typeparam name="T">接收JSON的数据类型</typeparam>
        /// <param name="url"></param>
        /// <param name="encoding"></param>
        /// <returns></returns>
        public static T GetJson <T>(string url, Encoding encoding = null) where T : IModel
        {
            string returnText = RequestUtility.HttpGet(url, encoding);

            //WeixinTrace.SendLog(url, returnText);


            if (returnText.Contains("errcode"))
            {
                //可能发生错误
                WxJsonResult errorResult = returnText.GetObject <WxJsonResult>();
                if (errorResult.errcode != ReturnCode.请求成功)
                {
                    //发生错误
                    throw new ApplicationException(
                              string.Format("微信请求发生错误!错误代码:{0},说明:{1}",
                                            (int)errorResult.errcode, errorResult.errmsg));
                }
            }

            T result = returnText.GetObject <T>();

            return(result);
        }