How can I load a web-page into a string in .net ?
i want the fastest way possible ...
How can I load a web-page into a string in .net ?
i want the fastest way possible ...
You could try the DownloadString method:
using (var client = new WebClient())
{
string result = client.DownloadString("http://www.google.com/");
}
VB.NET equivalent:
Using client = New WebClient()
Dim result As String = client.DownloadString("http://www.google.com/")
End Using
Short of writing your own HTTP client, you're pretty much stuck with WebRequest or WebClient (which leverages WebRequest for its work). A component of our website relies on downloading data from other webpages, and we recently replaced all of the code reliant on WebRequest/HttpWebRequest with our own Socket based code and gained considerable CPU cycles back, but it's a tricky job that will take one dev who is very familiar with HTTP protocol at least a week to complete. Not for the faint of heart.