Upon authorization, cookies are issued on the site, and each time the program is launched, this authentication is performed. So, is it possible to somehow save all the cookies once and then just read them from the file?
I am writing through the xNet library, sample code:
using (var req = new HttpRequest()) { HttpResponse resp; req.Cookies = new CookieDictionary(); req.KeepAlive = true; req.AddHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36"; resp = req.Get("http://rbc.ru/"); if (req.Cookies.ContainsKey("uid")) tbInfo.Text = "good"; else tbInfo.Text = "bad"; } A check in the code indicates that there are cookies, but I don’t know how to save them all to a file. I tried through the usual StreamWriter, but there I do not know where to go, because in the file gives either a boolean value or the name of the object / class / method.
UPDATE
I decided it myself, but I haven’t figured out how to recreate them in a new room.
The code may be overloaded with unnecessary, so if anyone knows the path easier and shorter, I will be grateful:
StreamWriter write = new StreamWriter(@"K:\aaa.txt"); for (int i = 0; i < req.Cookies.Count; i++) { write.Write(req.Cookies.Keys.ElementAt(i) + ": " + req.Cookies.Values.ElementAt(i) + Environment.NewLine); }