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
We used over 10 web hosting companies before we found Server Intellect. Their dedicated servers and add-ons were setup swiftly, in less than 24 hours. We were able to confirm our order over the phone. They respond to our inquiries within an hour. Server Intellect's customer support and assistance are the best we've ever experienced.
Add WebClient Control, a Click Button to the web page
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!