views:

68

answers:

1

Is there an easier way to write this? I know if i didnt need cookies i could have done

var sz = new WebClient().DownloadString(url);

But i need cookies bc of login data so i am stuck with this instead. Is there a way to make it short like the line above?

        request = (HttpWebRequest)HttpWebRequest.Create(url);
        request.CookieContainer = cookie;
        string sz;
        using (var r = request.GetResponse().GetResponseStream())
        {
            using(var r2 = (TextReader)new StreamReader(r))
            {
                sz= r2.ReadToEnd();
            }
        }
+2  A: 

Déjà vu... I think I've answered this question before! :-)

Take a look at http://stackoverflow.com/questions/1777221/c-using-cookiecontainer-with-webclient-class

Justin Grant