WebClient the class will do what you want:
string address = "http://stackoverflow.com/";
using (WebClient wc = new WebClient())
{
string content = wc.DownloadString(address);
}
As mentioned in the comments, you may prefer to use the asynchronous version DownloadStringto avoid blocking:
string address = "http://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;
}
}
Lukeh source
share