通过http cache来避免频繁调用接口

  try
            {
                WebClient client = new WebClient();
                client.Encoding = Encoding.UTF8;

                string datas;
                string GetZCS = HttpRuntime.Cache.Get("GetZCS_htmlStr") == null ? "" : HttpRuntime.Cache.Get("GetZCS_htmlStr").ToString ();

                if (GetZCS != "")
                {
                    datas = GetZCS;
                }
                else
                {
                    datas = client.DownloadString(Config.Kzr_Url);
                    HttpRuntime.Cache.Insert("GetZCS_htmlStr", datas, null, DateTime.Now.AddHours(1), TimeSpan.Zero);

                }



                if (!String.IsNullOrEmpty(datas))
                {
                    var Data = JsonHelper.Deserialize<Dictionary<string, object>>(datas);
                    var List = new List<Dictionary<string, object>>();
                    if (Data == null || Data["Datas"] == null)
                        List = JsonHelper.Deserialize<List<Dictionary<string, object>>>(datas);
                    else
                        List = JsonHelper.Deserialize<List<Dictionary<string, object>>>(JsonHelper.Serialize(Data["Datas"]));
                    foreach (Dictionary<string, object> item in List)
                    {
                        if (List.IndexOf(item) == 0)
                        {
                            kzr_FullName = (string)item["FundName"];
                            kzr_Rate = ((decimal)item["Rate"]).ToString();
                            kzr_Period = (item["Period"]).ToString();
                            kzr_MinRgAppend = Math.Ceiling(((decimal)item["minRgAppend"])).ToString();

                        }
                    }
                    if (List == null)
                    {
                        List = new List<Dictionary<string, object>>();
                    }
                    //Rmjj_DicResult.Add("Rmjj", List);

                }

            }
            catch (Exception ex)
            {
            }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值