开发者

load a webpage into a string ...fastest way

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜