0

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();
            }
        }

1 Answers1

2

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

Take a look at Using CookieContainer with WebClient class

Community
  • 1
  • 1
Justin Grant
  • 44,807
  • 15
  • 124
  • 208