Two classes in the System.Net namespace make it very easy to obtain the html of a remote web page. These are the HttpWebRequest and HttpWebResponse. Here's a quick demo.
The static method below makes an http request for a web page, and the resulting string of html within the http response is captured and returned to the caller.
//using System.Net;
//using System.IO;
static string GetHtmlPage(string strURL)
{
String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}
And to call the method:
string TheUrl = "http://www.something.com/Default.aspx";
string response = GetHtmlPage(TheUrl);
OR
WebClient webclient = new WebClient();
string source = webclient.DownloadString("http://www.something.com/Default.aspx");
Subscribe to:
Post Comments (Atom)
Ajax CalendarExtender displaying at wrong position in Chrome
< script type ="text/javascript" language ="javascript"> function onCalendarShown(sender, args)...
-
Suppose FieldName is the Bit field which tells whether the link should be visible true or false so design your gridview template like th...
-
There is no direct way to Expand/Collapse all panes in Accordion Extender. Using following java script, Accordion can be Expand/Collaps...
-
< script type ="text/javascript" language ="javascript"> function onCalendarShown(sender, args)...
nice article.. expecting more..
ReplyDelete