Advertisement
Guest User

Untitled

a guest
Jul 11th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. private static CookieContainer _cc = new CookieContainer();
  2. private static CookieContainer CookiesCont
  3. {
  4. get
  5. {
  6. if (_cc == null)
  7. _cc = new CookieContainer();
  8.  
  9. return _cc;
  10. }
  11. }
  12.  
  13. public static string Auth(string url = "https://hh.ru/account/login", string user, string pass)
  14. {
  15. var wr = (HttpWebRequest)WebRequest.Create("http://hh.ru");
  16. wr.CookieContainer = CookiesCont;
  17. wr.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36";
  18. wr.ContentType = "application/x-www-form-urlencoded";
  19. wr.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
  20. wr.Referer = "https://smolensk.hh.ru/account/login?state=mismatch&backurl=https://smolensk.hh.ru/&login=repariofirm@gmail.com";
  21. wr.KeepAlive = true;
  22. wr.AllowAutoRedirect = true;
  23.  
  24. try
  25. {
  26. using (WebResponse response = wr.GetResponse())
  27. {
  28. if (!string.IsNullOrEmpty(response.Headers["Set-Cookie"]))
  29. sCookies = response.Headers["Set-Cookie"];
  30. }
  31. }
  32. catch (Exception ex)
  33. {
  34. }
  35.  
  36. var start = sCookies.IndexOf("_xsrf");
  37. var end = sCookies.IndexOf(';');
  38.  
  39. string xsrf = sCookies.Substring(start + 6, end - start - 6);
  40. string data = string.Format("backUrl:https://hh.ru/&failUrl:/account/login?backurl=/&role=&username:{0}&password:{1}&_xsrf={2}", user, pass, xsrf);
  41.  
  42. wr = (HttpWebRequest)HttpWebRequest.Create(url);
  43. wr.Method = "POST";
  44. wr.CookieContainer = CookiesCont;
  45. wr.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36";
  46. wr.ContentType = "application/x-www-form-urlencoded";
  47. wr.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
  48. wr.Referer = "https://smolensk.hh.ru/account/login?state=mismatch&backurl=https://smolensk.hh.ru/&login=repariofirm@gmail.com";
  49. wr.KeepAlive = true;
  50. wr.AllowAutoRedirect = true;
  51.  
  52. try
  53. {
  54. var buffer = Encoding.UTF8.GetBytes(data);
  55. wr.ContentLength = buffer.Length;
  56.  
  57. using (var writer = wr.GetRequestStream())
  58. {
  59. writer.Write(buffer, 0, buffer.Length);
  60. }
  61.  
  62. HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
  63. //Считываем данные из запроса
  64. using (StreamReader DataRead = new StreamReader(response.GetResponseStream()))
  65. {
  66. //Записываем в строку
  67. return DataRead.ReadToEnd();
  68. }
  69. }
  70. catch (WebException WE)
  71. {
  72. //Сообщение об ошибке
  73. return WE.Message;
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement