Making HTTP request and get response without a Browser( in command line)

Little code snippet which allows you to access website content with minimal code.


using system;
using system.collection.generic;
using system.linq;
using system.text;
using system.net;
using system.io;
namespace webrequest
{
class programm
{
static void main(string[] args)
{
WebRequest req = WebRequest.Create(http://www.microsoft.com);
WebResponse resp = req.GetResponse();
StreamReader reader = new StreamReader(resp.GetResponseStream(),Encoding.ASCII);
Console.WriteLine(reader.ReadToEnd();
}
}
}

 

ref: http://msdn.microsoft.com/en-us/library/system.net.webrequest(v=VS.100).aspx

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 )

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 )

w

Connecting to %s