I'm trying to login to website and download some pages as it see logged user in C#. I have class, where are functions to send POST to login page to login. I have verified, that I actually log in, but data's are not keeped, so when I download HTML of the page I need, I get page saying to log in. I found this, but I don't know how to implement it. I have class with two funtions: Login() used to login to website, based on this example:
using(WebClient client = new WebClient())
{
System.Collections.Specialized.NameValueCollection reqparm = new System.Collections.Specialized.NameValueCollection();
reqparm.Add("param1", "<any> kinds & of = ? strings");
reqparm.Add("param2", "escaping is already handled");
byte[] responsebytes = client.UploadValues("http://localhost", "POST", reqparm);
string responsebody = Encoding.UTF8.GetString(responsebytes);
}
Then, second function DownloadHtml(string url), contains this:
using (WebClient client = new WebClient()) {
client.Encoding = Encoding.UTF8;
html = client.DownloadString(url);
return html;
}
How to save cookis in Login() and use them in DownloadHtml() to see the page as logged user? Or shouldn't I use WebClient? If no, what should I use? Thanks.