im trying to read a website and i keep getting the exception "underlying connection was closed"

WebClient w = new WebClient();
Stream s = w.openRead(addr);

and yes addr has a 'http://' prefix

why am i getting this exception every time?

1st of all, you have to add a new namespace (using System.Net;)
Now I will show you a simple example of how to get the website`s text:

List<string> list = new List<string>();
        private void GetAllText()
            WebRequest request = WebRequest.Create("");
            WebResponse response = request.GetResponse();
            using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                while (!sr.EndOfStream)
                    list.Add(sr.ReadLine()); //line by line it writes into a list<T>.

That is an odd example Mitja, you only need 2 lines of code for this, you defiantly don't want to separate all the strings into a generic list like that. And its unnecessary to handle the request and response like that. Just use your framework classes.

// Create web client.
        WebClient client = new WebClient();

        // Download string.
        string value = client.DownloadString("");

Edited 5 Years Ago by Diamonddrake: n/a

my code compiles why would you assume that this is a compiler issue... its the webclient class thats not working correctly im trying to figure out why

This article has been dead for over six months. Start a new discussion instead.