Search code examples
c#webclientdownloadstring

Webclient.DownloadString does not retrieve the whole page


I'm trying to retrieve the source of a site with WebClient.DownloadString, but when i debug the string I'm writing the source to it seems to cut off a part of the html source.

Text visualiser in VS: https://i.imgur.com/AWiTTqI.png

Browser debug: enter image description here

Code:

public string GetWebpageSource()
{
    using (WebClient client = new WebClient())
    {
        client.Headers[HttpRequestHeader.UserAgent] = "Mozilla / 5.0(Windows NT 10.0; Win64; x64; rv: 44.0) Gecko / 20100101 Firefox / 44.0";
        client.Encoding = Encoding.UTF8;
        string htmlcode = client.DownloadString("http://2007.runescape.wikia.com/wiki/Bandos%20page%201");
        return htmlcode;
    }
}

So I'm wondering why it does that? If there's additional info needed, I will post it. Thanks for reading!


Solution

  • Thanks to people from SO I've found the 'problem'. The text visualiser in VS gave me an indication that the text was cut off, but this was not the problem when writing the source to a file. So I thought it did not download the whole page because the text in the text visualiser. So the lession I've learned is do NOT trust the text visualiser!

    By further debugging from the text file I could solve my problems :)