Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- csrfmiddlewaretoken "7e9001a3c0000f11099c11h119745e30"
- username "логин"
- password "пароль"
- next "/about/"
- WebResponse Response;
- HttpWebRequest Request;
- Uri url = new Uri("http://00.00.00.000:0000/accounts/login/");
- CookieContainer cookieContainer = new CookieContainer();
- Request = (HttpWebRequest)WebRequest.Create(url);
- Request.Method = "GET";
- Request.CookieContainer = cookieContainer;
- Response = Request.GetResponse(); //1 раз получил csrfmiddlewaretoken
- string Parametros = "csrfmiddlewaretoken=" + cookieContainer.GetCookies(url)["csrftoken"].Value + "&username=логин&password=пароль&next=/about/";
- Request = (HttpWebRequest)WebRequest.Create(url);
- //вот тут получается мне выдадут потом новый токен, а без использования этого я не знаю как сформировать новый запрос
- Request.Method = "POST";
- Request.ContentType = "application/x-www-form-urlencoded";
- Request.CookieContainer = cookieContainer;
- Request.Headers.Add("Cookie", Response.Headers.Get("Set-Cookie"));
- byte[] byteArray = Encoding.UTF8.GetBytes(Parametros);
- Request.ContentLength = byteArray.Length;
- Response = Request.GetResponse();
- <form method="POST" action="/accounts/login/" class="well" autocomplete="off"> <div style="display:none"><input type="hidden" name="csrfmiddlewaretoken" value="7e9001a3c2801f25097c11e119745e31" /></div>
- Uri url = new Uri("http://00.00.00.000:0000/accounts/login/");
- CookieContainer cookieContainer = new CookieContainer();
- HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
- httpWebRequest.Method = "GET";
- httpWebRequest.CookieContainer = cookieContainer;
- HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
- string Parametros = "csrfmiddlewaretoken=" + cookieContainer.GetCookies(url)["csrftoken"].Value + "&username=логин&password=пароль&next=/about/";
- Console.WriteLine(Parametros);
- //Paremetros "csrfmiddlewaretoken=d113dc9681a9ed800397f6164b608114&username=логин&password=пароль&next=/about/"
- httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
- httpWebRequest.Method = "POST";
- httpWebRequest.ContentLength = Parametros.Length;
- httpWebRequest.ContentType = "application/x-www-form-urlencoded";
- httpWebRequest.CookieContainer = cookieContainer;
- //httpWebRequest.Headers.Add("Cookie", httpWebRequest.Headers.Get("Set-Cookie"));
- using (Stream stream = httpWebRequest.GetRequestStream())
- {
- byte[] paramAsBytes = Encoding.Default.GetBytes(Parametros);
- stream.Write(paramAsBytes, 0, paramAsBytes.Count());
- }
- httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();//тут получаю 401 Несанкционированный
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement