Download file from URL to a string

前端 未结 5 502
渐次进展
渐次进展 2020-12-05 17:03

How could I use C# to download the contents of a URL, and store the text in a string, without having to save the file to the hard drive?

5条回答
  •  渐次进展
    2020-12-05 17:34

    Use a WebClient

    var result = string.Empty;
    using (var webClient = new System.Net.WebClient())
    {
        result = webClient.DownloadString("http://some.url");
    }
    

提交回复
热议问题