Hi, I've been trying and failing at
this for hours and I've come to a point of desperate frustration. I
am trying to write a console app that connects to any given website,
say MSN.com, downloads and then displays the HTML code for that site.
Can anyone please explain to me, step-by-step, how to do this
(preferably with code examples). Thanks, it would be greatly
appreciated.

Please help: console connect to a webpage
Roto
try it before change anything to make sure it works and you understood the code
Philippe Cand
NOTE: Remove line with proxy class if you do not have proxy server
LotusExigeS1
For more info take a look at WebClient class
hope this helps
Redsome
double digger
ARme
talismax
YA say hello
This should work:
using
System;using
System.Collections.Generic;using
System.Text;using
System.Net;using
System.IO;namespace
WebRequestConsole{
class Program{
static void Main(string[] args){
try{
// HttpWebRequest not created directly, uses WebRequest factory method HttpWebRequest request = WebRequest.Create("http://www.msn.com/") as HttpWebRequest; if(request != null){
// Cast response to HttpWebResponse using(HttpWebResponse response = request.GetResponse() as HttpWebResponse){
Stream stream = response.GetResponseStream(); // Read characters from Stream 1K at a time using(StreamReader reader = new StreamReader(stream)){
char[] buffer = new char[1024]; int count; while((count = reader.Read(buffer, 0, 1024)) > 0){
Console.Write(new string(buffer, 0, count));}
reader.Close();
}
response.Close();
}
}
}
catch(Exception ex){
Console.Error.WriteLine(ex.ToString());}
Console.ReadLine();}
}
}