Advertisement
Guest User

Untitled

a guest
Aug 28th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. csrfmiddlewaretoken "7e9001a3c0000f11099c11h119745e30"
  2. username "логин"
  3. password "пароль"
  4. next "/about/"
  5.  
  6. WebResponse Response;
  7. HttpWebRequest Request;
  8. Uri url = new Uri("http://00.00.00.000:0000/accounts/login/");
  9. CookieContainer cookieContainer = new CookieContainer();
  10.  
  11. Request = (HttpWebRequest)WebRequest.Create(url);
  12. Request.Method = "GET";
  13. Request.CookieContainer = cookieContainer;
  14. Response = Request.GetResponse(); //1 раз получил csrfmiddlewaretoken
  15.  
  16. string Parametros = "csrfmiddlewaretoken=" + cookieContainer.GetCookies(url)["csrftoken"].Value + "&username=логин&password=пароль&next=/about/";
  17.  
  18. Request = (HttpWebRequest)WebRequest.Create(url);
  19. //вот тут получается мне выдадут потом новый токен, а без использования этого я не знаю как сформировать новый запрос
  20. Request.Method = "POST";
  21. Request.ContentType = "application/x-www-form-urlencoded";
  22. Request.CookieContainer = cookieContainer;
  23. Request.Headers.Add("Cookie", Response.Headers.Get("Set-Cookie"));
  24. byte[] byteArray = Encoding.UTF8.GetBytes(Parametros);
  25. Request.ContentLength = byteArray.Length;
  26. Response = Request.GetResponse();
  27.  
  28. <form method="POST" action="/accounts/login/" class="well" autocomplete="off"> <div style="display:none"><input type="hidden" name="csrfmiddlewaretoken" value="7e9001a3c2801f25097c11e119745e31" /></div>
  29.  
  30. Uri url = new Uri("http://00.00.00.000:0000/accounts/login/");
  31.  
  32. CookieContainer cookieContainer = new CookieContainer();
  33. HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
  34. httpWebRequest.Method = "GET";
  35. httpWebRequest.CookieContainer = cookieContainer;
  36. HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  37.  
  38. string Parametros = "csrfmiddlewaretoken=" + cookieContainer.GetCookies(url)["csrftoken"].Value + "&username=логин&password=пароль&next=/about/";
  39. Console.WriteLine(Parametros);
  40. //Paremetros "csrfmiddlewaretoken=d113dc9681a9ed800397f6164b608114&username=логин&password=пароль&next=/about/"
  41.  
  42. httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
  43. httpWebRequest.Method = "POST";
  44. httpWebRequest.ContentLength = Parametros.Length;
  45. httpWebRequest.ContentType = "application/x-www-form-urlencoded";
  46. httpWebRequest.CookieContainer = cookieContainer;
  47. //httpWebRequest.Headers.Add("Cookie", httpWebRequest.Headers.Get("Set-Cookie"));
  48.  
  49. using (Stream stream = httpWebRequest.GetRequestStream())
  50. {
  51. byte[] paramAsBytes = Encoding.Default.GetBytes(Parametros);
  52. stream.Write(paramAsBytes, 0, paramAsBytes.Count());
  53. }
  54. httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();//тут получаю 401 Несанкционированный
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement