开发者

load a webpage into a string ...fastest way

开发者 https://www.devze.com 2023-01-16 05:44 出处:网络
How can I load a web-page into a s开发者_如何转开发tring in .net ? i want the fastest way possible ...You could try the DownloadString method:

How can I load a web-page into a s开发者_如何转开发tring 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消