posts - 54, comments - 158, trackbacks - 4

My Links

Archives

Post Categories

Projects

Web Dev

Pulling Web Content with C#

A simple way to perform a 'wget' on a url with c#. This method will return the 'html source' of a webpage.

static string GetContent(string url)
{
WebClient client = new WebClient();

client.Headers.Add("user-agent",

"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

Stream data = client.OpenRead(url);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
reader.Close();

return s;
}

Print | posted on Saturday, November 15, 2008 1:05 PM | Filed Under [ Web Programming ]

kick it on DotNetKicks.com

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 1 and 6 and type the answer here:

Powered by: