I have been trying to get a clear answer on how to download a page’s HTML as a string for months, but have made zero progress. I can mess with all of the parsing myself, and I’ll be able to figure out where it needs to fit into the application as I mess around with it. I would be very very grateful if someone could give me a clear code block to download a page’s HTML as a string from a given url.
Share
Well the simplest way is to use
WebClient:where the event handler then takes whatever action it needs to.
However, it’s worth bearing in mind that
WebClientdoes rather a lot of work on the UI thread (despite the “async” part) – if this is for a production app, you probably want to useWebRequestdirectly. That’s significantly more work (you end up with aStreamfrom theWebResponse, so you need to use the appropriate string encoding and construct aStreamReaderaround it in order to read a string).