コード例 #1
0
        /// <summary>
        /// Home page.
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            var welGeekModel = new WelComeGeekModel();
            var geekStr      = WebCommonHelper.HttpGetWebRequest("http://geek.csdn.net/service/news/get_news_list?size=20&type=HackCount");

            if (!string.IsNullOrEmpty(geekStr))
            {
                welGeekModel = JsonConvert.DeserializeObject <WelComeGeekModel>(geekStr);
            }
            ViewBag.Html = welGeekModel.html;
            return(View());
        }
コード例 #2
0
 /// <summary>
 /// Get api data
 /// </summary>
 /// <typeparam name="T">data type</typeparam>
 /// <param name="requestUrl">request url</param>
 /// <param name="paramsDic">params dictionary</param>
 /// <param name="isPost">is post way get data</param>
 /// <returns>Api data,if error return default T</returns>
 public T GetDataApi <T>(string requestUrl, IDictionary <string, object> paramsDic = null, bool isPost = false)
 {
     try
     {
         var resultStr = isPost
             ? WebCommonHelper.CreatePostHttpResponse(requestUrl, paramsDic, 16000, null, Encoding.UTF8)
             : WebCommonHelper.HttpGetWebRequest(requestUrl);
         if (string.IsNullOrEmpty(resultStr))
         {
             return(default(T));
         }
         var resultModel = JsonConvert.DeserializeObject <ApiResultModel <T> >(resultStr);
         if (resultModel == null)
         {
             return(default(T));
         }
         return(resultModel.Data);
     }
     catch (Exception)
     {
         return(default(T));
     }
 }