How can i download a website content to a string?

后端 未结 3 1663
庸人自扰
庸人自扰 2020-12-21 10:51

I tried this and i want that the source content of the website will be download to a string:

public partial class Form1 : Form
    {
        WebClient client         


        
3条回答
  •  独厮守ぢ
    2020-12-21 11:24

    No need for async, really:

    var result = new System.Net.WebClient().DownloadString(url)
    

    If you don't want to block your UI, you can put the above in a BackgroundWorker. The reason I suggest this rather than the Async methods is because it is dramatically simpler to use, and because I suspect you are just going to stick this string into the UI somewhere anyway (where BackgroundWorker will make your life easier).

提交回复
热议问题