.NET WebClient: Where is DownloadString?

2019-07-22 04:45发布

问题:

I'm probably missing something here, but when I use WebClient and look for the DownloadString method (as found in a book example), I only see DownloadStringAsync.

What Import am I missing?

回答1:

Are you using Silverlight? Only the Async version is available in Silverlight. Otherwise, the .NET 4 Framework and below (except 1.x) have the DownloadString() method.

http://msdn.microsoft.com/en-us/library/ms144200.aspx



回答2:

as indicated here, it looks like the DownloadString method is part of System.Net.



回答3:

Well, I think you're creating a Silverlight application. In that case it is a normal thing: you will find usually only asynchronous methods in Silverlight applications; this makes your UI more responsive because operations will be executed in another thread without blocking it.

Try to create a desktop application (Console Application, WPF, etc.) and you will find the method you're looking for.