Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static CookieContainer _cc = new CookieContainer();
- private static CookieContainer CookiesCont
- {
- get
- {
- if (_cc == null)
- _cc = new CookieContainer();
- return _cc;
- }
- }
- public static string Auth(string url = "https://hh.ru/account/login", string user, string pass)
- {
- var wr = (HttpWebRequest)WebRequest.Create("http://hh.ru");
- wr.CookieContainer = CookiesCont;
- wr.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36";
- wr.ContentType = "application/x-www-form-urlencoded";
- wr.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
- wr.Referer = "https://smolensk.hh.ru/account/login?state=mismatch&backurl=https://smolensk.hh.ru/&login=repariofirm@gmail.com";
- wr.KeepAlive = true;
- wr.AllowAutoRedirect = true;
- try
- {
- using (WebResponse response = wr.GetResponse())
- {
- if (!string.IsNullOrEmpty(response.Headers["Set-Cookie"]))
- sCookies = response.Headers["Set-Cookie"];
- }
- }
- catch (Exception ex)
- {
- }
- var start = sCookies.IndexOf("_xsrf");
- var end = sCookies.IndexOf(';');
- string xsrf = sCookies.Substring(start + 6, end - start - 6);
- string data = string.Format("backUrl:https://hh.ru/&failUrl:/account/login?backurl=/&role=&username:{0}&password:{1}&_xsrf={2}", user, pass, xsrf);
- wr = (HttpWebRequest)HttpWebRequest.Create(url);
- wr.Method = "POST";
- wr.CookieContainer = CookiesCont;
- wr.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36";
- wr.ContentType = "application/x-www-form-urlencoded";
- wr.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
- wr.Referer = "https://smolensk.hh.ru/account/login?state=mismatch&backurl=https://smolensk.hh.ru/&login=repariofirm@gmail.com";
- wr.KeepAlive = true;
- wr.AllowAutoRedirect = true;
- try
- {
- var buffer = Encoding.UTF8.GetBytes(data);
- wr.ContentLength = buffer.Length;
- using (var writer = wr.GetRequestStream())
- {
- writer.Write(buffer, 0, buffer.Length);
- }
- HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
- //Считываем данные из запроса
- using (StreamReader DataRead = new StreamReader(response.GetResponseStream()))
- {
- //Записываем в строку
- return DataRead.ReadToEnd();
- }
- }
- catch (WebException WE)
- {
- //Сообщение об ошибке
- return WE.Message;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement