Making HTTP Requests Without a Browser


Expains how to Making HTTP Requests Without a Browser through program.

Create one console project.and few lines of code given below.



Using System.Net;
using System.IO;



static void Main(string[] args)
{
WebRequest req = WebRequest.Create("http://www.google.com");
WebResponse response = req.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(),Encoding.ASCII);
Console.WriteLine(sr.ReadToEnd());

}





And see the output in console window.


Comments

Author: krishnavenikaladi28 Feb 2010 Member Level: Gold   Points : 2

hi Bommala

I tried u'r code but i am getting following error.Can u correct me


Unhandled Exception: System.Net.WebException: The remote name could not be resol
ved: 'www.dotnetspider.com'
at System.Net.HttpWebRequest.GetResponse()
at ConsoleApplication25.Program.Main(String[] args) in C:\Documents and Setti
ngs\house\My Documents\Visual Studio 2008\Projects\ConsoleApplication25\ConsoleA
pplication25\Program.cs:line 30
Press any key to continue . . .

Author: bommala02 Mar 2010 Member Level: Silver   Points : 1

hi krishnavenikaladi ,

Please make sure you type address correctly.
Type as http://www.dotnetspider.com in WebRequest.Create(..) function.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: