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();
myReader.Close();
Console.Write (webPageHtml);
myReader.Close ();

3. Thats it.


Keep Smiling 🙂

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: