Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8567419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:52:49+00:00 2026-06-11T17:52:49+00:00

This is the function: private static HtmlAgilityPack.HtmlDocument getHtmlDocumentWebClient(string url, bool useProxy, string proxyIp, int

  • 0

This is the function:

private static HtmlAgilityPack.HtmlDocument getHtmlDocumentWebClient(string url, bool useProxy, string proxyIp, int proxyPort, string usename, string password)
        {
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            WebClient client = new WebClient();
            //client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            client.Credentials = CredentialCache.DefaultCredentials;
            client.Proxy = WebRequest.DefaultWebProxy;
            if (useProxy)
            {
                //Proxy                
                if (!string.IsNullOrEmpty(proxyIp))
                {
                    WebProxy p = new WebProxy(proxyIp, proxyPort);
                    if (!string.IsNullOrEmpty(usename))
                    {
                        if (password == null)
                            password = string.Empty;
                        NetworkCredential nc = new NetworkCredential(usename, password);
                        p.Credentials = nc;
                    }
                }
            }
            Stream data = client.OpenRead(url);
            doc.Load(data);
            data.Close();
            return doc;
        }

Im getting links each itertion in my program and after few times the variable url is:

http://appldnld.apple.com/iTunes10/041-7196.20120912.Ber43/iTunesSetup.exe

If i mtrying this link in my InternetExplorer it will try to download the file.
But in my program its trying to Load it in the line:

doc.Load(data);

Wich make after some time the program to freeze stuck and in the end when i force to END the application in Task Manager the program throw me an exception:

StackOverFlowException was unhandled 

An unhandled exception of type 'System.StackOverflowException' occurred in HtmlAgilityPack.dll

System.StackOverflowException was unhandled
Message: An unhandled exception of type 'System.StackOverflowException' occurred in HtmlAgilityPack.dll

Now i used a breakpoint and the problem happen on the line:

doc.Load(data);

The question is how should i handle in cases of this links ? Should i ignore them by try and catch or maybe i should consider this as a link ? What if sometime in the future i will want to use this links to download the exe files so maybe try and ctach is not a good idea ?


Edited:

This is how the getHtmlDocumentWebClient look like now:

private  static HtmlAgilityPack.HtmlDocument getHtmlDocumentWebClient(string url, bool useProxy, string proxyIp, int proxyPort, string usename, string password)
        {

            HttpWebRequest myHttpWebRequest = null;     //Declare an HTTP-specific implementation of the WebRequest class.
            HttpWebResponse myHttpWebResponse = null;   //Declare an HTTP-specific implementation of the WebResponse class
            //Create Request
            myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
            myHttpWebRequest.Method = "GET";
            myHttpWebRequest.ContentType = "text/html; encoding='utf-8'";
            //Get Response
            myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();

            Stream data = myHttpWebResponse.GetResponseStream();//client.OpenRead(url);
            doc.Load(data);
            data.Close();
            return doc;
        }

Same problem yet. Whats wrong with the function now and how do i do the actual checking/s for text/html content ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:52:50+00:00Added an answer on June 11, 2026 at 5:52 pm

    You should check the Content-Type before trying to parse the response as HTML.
    If it isn’t text/html or one of its variants, don’t parse it.

    To get the Content-Type, you will need to use HttpWebRequest instead of WebClient.
    You can then check response.Headers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Check this function. private static IEnumerable<string> FindAccessibleDatabases() { var connectionStrings = new List<string>(); Parallel.For(0,
here it is, using this function: private static void write(String Swrite) throws IOException {
I write this function for merging two arrays. private static int[] Merge(int[] array1, int[]
So given this input string: =?ISO-8859-1?Q?TEST=2C_This_Is_A_Test_of_Some_Encoding=AE?= And this function: private string DecodeSubject(string input) {
I have a private function like this in my controller. private UserDetails GetUserDetails(int userid)
I have a ComboBox with a label function like this one: private function fieldLabelFunction(item:Object):String
In one of my classes, I have got code: private static void Notify(string url,
I noticed this function in a .NET project I am working on. private static
I'm building a program that uses a WriteAllLines generic function: private static void WriteAllLines(string
I have this function: public static Bitmap getResizedBitmap(Bitmap bm,Context c) { int width =(int)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.