Making HTTP Requests without a Browser

Hi everyone…

Here is way to make HTTP requests without using a browser. 

1.  Before starting add an reference to

using System.Net

2. After that following code snippet will save the html of any webpage which will be mentioned in url variable to a string named as webPageHtml.  

string url = “<you web pages url goes here>”;
WebRequest myWebRequest = HttpWebRequest.Create(url);
Stream myWebStream = myWebRequest.GetResponse().GetResponseStream();
StreamReader myReader = new StreamReader(myWebStream);
string webPageHtml = myReader.ReadToEnd();
Console.Write (webPageHtml);
myReader.Close ();

3. Thats it.

Keep Smiling 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: