Get Web Page Content for Given URL

Posted by Lakhangarg under ASP.NET category on | Views : 3313
First This Piece of Code will Send a request for given URL.
and will get the response for that request. the Response object will return a data in the form of stream and this code will read the strean data With the help of StreamReader and then write that data into a string.

Uri uri = new Uri("");
//Create the request object

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.UserAgent = "Get Content";
WebResponse resp = req.GetResponse();
Stream stream = resp.GetResponseStream();
StreamReader sr = new StreamReader(stream);
string s = sr.ReadToEnd();

Comments or Responses

Login to post response