解决方法
WebClient
课程会做你想要的:
string address = "https://stackoverflow.com/"; using (WebClient wc = new WebClient()) { string content = wc.DownloadString(address); }
如评论中所述,您可能更喜欢使用DownloadString的异步版本来避免阻塞:
string address = "https://stackoverflow.com/"; using (WebClient wc = new WebClient()) { wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadCompleted); wc.DownloadStringAsync(new Uri(address)); } // ... void DownloadCompleted(object sender,DownloadStringCompletedEventArgs e) { if ((e.Error == null) && !e.Cancelled) { string content = e.Result; } }