Esempio n. 1
0
        private static string GetHtml(string sUrl, System.Text.Encoding sEncode, int iMaxRetry, int iCurrentRetry)
        {
            string result = string.Empty;

            try
            {
                Uri                    requestUri     = new Uri(sUrl);
                WebRequest             webRequest     = WebRequest.Create(requestUri);
                WebResponse            response       = webRequest.GetResponse();
                System.IO.Stream       responseStream = response.GetResponseStream();
                System.IO.StreamReader streamReader   = new System.IO.StreamReader(responseStream, sEncode);
                result = streamReader.ReadToEnd();
                streamReader.Close();
                response.Close();
            }
            catch
            {
                iCurrentRetry++;
                if (iCurrentRetry <= iMaxRetry)
                {
                    HttpCollects.GetHtml(sUrl, sEncode, iMaxRetry, iCurrentRetry);
                }
            }
            return(result);
        }
Esempio n. 2
0
        public static string GetHtmlWithTried(string sUrl, System.Text.Encoding sEncode, int iMaxRetry)
        {
            string empty = string.Empty;

            return(HttpCollects.GetHtml(sUrl, sEncode, iMaxRetry, 0));
        }