示例#1
0
        public string GetRawJsonFromUrl(string url)
        {
            string cachePath = GetCachePathFromUrl(url);

            if (!this.CacheTimeSeconds.HasValue || !CacheUtility.ReadFile(cachePath, out string rawJson, this.CacheTimeSeconds))
            {
                try
                {
                    rawJson = WebClient.DownloadString(url);
                    if (rawJson == null)
                    {
                        // SOMETIME NULL COMES BACK. TRY A SECOND TIME IF THAT HAPPENS
                        rawJson = WebClient.DownloadString(url);
                    }
                }
                catch (Exception ex)
                {
                    return(null);
                }
                if (!this.CacheTimeSeconds.HasValue || (this.CacheTimeSeconds.HasValue && this.CacheTimeSeconds.Value > 0))
                {
                    CacheUtility.WriteFile(cachePath, rawJson);
                }
            }

            return(rawJson);
        }
示例#2
0
        public static string GetRawJsonFromUrl(string url, int?cacheTimeSeconds = null)
        {
            string cachePath = GetCachePathFromUrl(url);

            if (!cacheTimeSeconds.HasValue || !CacheUtility.ReadFile(cachePath, out string rawJson, cacheTimeSeconds))
            {
                try
                {
                    rawJson = WebClient.DownloadString(url);
                }
                catch
                {
                    return(null);
                }
                if (!cacheTimeSeconds.HasValue || (cacheTimeSeconds.HasValue && cacheTimeSeconds.Value > 0))
                {
                    CacheUtility.WriteFile(cachePath, rawJson);
                }
            }

            return(rawJson);
        }