Exemple #1
0
        public static RequestResult <T> GetCallApi <T>(string address, bool runInBackgroud = false)
        {
            if (address.Contains("?"))
            {
                try
                {
                    var urlArr  = address.Split('?');
                    var parmStr = urlArr[1];
                    var parmArr = parmStr.Split('&').Select(x => x.Split('=').ToArray()).ToList();
                    parmArr.ForEach(x => x[1] = System.Web.HttpUtility.UrlEncode(x[1]));
                    urlArr[1] = string.Join("&", parmArr.Select(x => string.Join("=", x)).ToArray());
                    address   = string.Join("?", urlArr);
                }
                catch { }
            }
            //address = string.Join('?', address.Split('?').se
            Logger.Error(address);
            var result = WebApiVisitor.GetAccessApi <T>(address, runInBackgroud);

            Logger.Error("测试result" + result == null ? ":null" : result.Result.ToString());
            if (result.Result == ResultStatus.Success)
            {
                return(result);
            }
            else
            {
                Logger.Error(result.Message);

                return(null);
            }
        }
Exemple #2
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);
                if (CheckReLogin <T>(obj))
                {
                    obj = WebApiVisitor.GetAccessApi <T>(address);
                }
            }
            catch (Exception)
            {
                obj = new RequestResult <T>()
                {
                    Result  = ResultStatus.Default,
                    Data    = default(T),
                    Message = "WebApi访问失败"
                };
            }
            return(obj);
        }