Esempio n. 1
0
        public HtmlDocument GetWebRequest()
        {
            HtmlDocument document = new HtmlDocument();

            byte[] responseBytes;
            if (!cache.IsCachedUrl(Url))
            {
                responseBytes = httpClient.DownloadData(Url);
                CacheDb.SaveCache(Url, responseBytes);
            }
            else
            {
                responseBytes = cache.GetCachedUrl(Url);
            }
            MemoryStream mStream = new MemoryStream(responseBytes);

            document.Load(mStream);
            return(document);
        }
Esempio n. 2
0
        public HtmlDocument GetWebRequest(String Url)
        {
            for (int RetryCount = 1; true; RetryCount++)
            {
                try
                {
                    HttpClient httpClient = new HttpClient();

                    HtmlDocument document = new HtmlDocument();
                    document.OptionAutoCloseOnEnd = true;
                    document.OptionCheckSyntax    = true;
                    document.OptionFixNestedTags  = true;
                    //document.OptionWriteEmptyNodes = true;
                    byte[] responseBytes;
                    if (EnableCaching && !cache.IsCachedUrl(Url))
                    {
                        responseBytes = httpClient.DownloadData(Url);
                        CacheDb.SaveCache(Url, responseBytes);
                    }
                    else if (EnableCaching)
                    {
                        responseBytes = cache.GetCachedUrl(Url);
                    }
                    else
                    {
                        responseBytes = httpClient.DownloadData(Url);
                    }
                    MemoryStream mStream = new MemoryStream(responseBytes);
                    document.Load(mStream);
                    return(document);
                }
                catch (Exception ex)
                {
                    if (RetryCount == MaxRetryCount)
                    {
                        throw ex;
                    }
                }
            }
        }