DotNet Tutorials

V4 Dot Net Tutorials

Server Intellect Cloud Hosting

 WebClient to retrieve web page from URL in ASP.NET(C#)

This tutorial will show you how to use WebClient to retrieve web page with C# in ASP.NET 2.0. The .NET framework provides an easy to use interface for retrieving resources from a specified URL. Use WebClient Control to perform linking and loading specified URL.

Design three controls in the web page. There are a TextBox, a Button and a Label

Add WebClient Control, a Click Button to the web page

Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!

WebClient objWebClient = new WebClient();

lblHTML.Text = lblHTML.Text+strHeader + "-" + objWebClient.Headers[strHeader] + "<br>";

foreach (string strHeader in objWebClient.Headers)
{
lblHTML.Text = lblHTML.Text+strHeader + "-" + objWebClient.Headers[strHeader] + "<br>";
}
UTF8Encoding objUTF8 = new UTF8Encoding();
string strRequestHTML = objUTF8.GetString(objWebClient.DownloadData(txtUrl.Text));

lblHTML.Text = "<p><b>Response Header Information:</b>";
foreach(string strHeader in objWebClient.ResponseHeaders)
{
lblHTML.Text = strHeader + "-" + objWebClient.ResponseHeaders["strHeader"];
}
lblHTML.Text = lblHTML.Text + strRequestHTML;



Looking for the VB.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!

Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!