Как отследить, куда страница при залогивании тебя перенаправляет в браузере? - C#
Формулировка задачи:
Как отследить куда страница при залогивании тебя перенаправляет в браузере, это происходит очень быстро и нужно понять через какие страницы меня перекидывает
пытаюсь залогиниться вот здесь http://profitcentr.com/, через HttpWebRequest, кто поможет, огромное спасибо! а то мои силы уже иссякли в поисках информации
Решение задачи: «Как отследить, куда страница при залогивании тебя перенаправляет в браузере?»
textual
Листинг программы
private CookieContainer cookies = new CookieContainer();
private void Button_Click(object sender, RoutedEventArgs e)
{
textblock.Text = "";
HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create("http://profitcentr.com/");
request1.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request1.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0";
request1.ContentType = "application/x-www-form-urlencoded";
HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
this.cookies.Add(response1.Cookies);
/*
foreach (string key in response1.Headers.AllKeys)
{
textblock.Text += key + ": " + response1.Headers[key] + "\n";
}
textblock.Text += "\n";
textblock.Text += response1.Cookies.Count.ToString() + "\n";
textblock.Text += "\n";
foreach (Cookie cookie in response1.Cookies)
{
textblock.Text += cookie.Name + ": " + cookie.Value + "\n";
}
textblock.Text += "\n";
*/
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://profitcentr.com/captcha_1.php");
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0";
request.ContentType = "application/x-www-form-urlencoded";
request.CookieContainer = this.cookies;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.Drawing.Bitmap img = new System.Drawing.Bitmap(response.GetResponseStream());
image.Source = BitmapConversion.ToWpfBitmap(img);
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create("http://profitcentr.com/login_vh.php");
request2.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request2.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0";
request2.ContentType = "application/x-www-form-urlencoded";
request2.Method = "POST";
request2.CookieContainer = this.cookies;
request2.Timeout = 120000;
byte[] sentData = Encoding.GetEncoding(1251).GetBytes(Uri.EscapeDataString("username=12345&nospam=25.11.2014&password=123456&captcha=" + textbox.Text));
request2.ContentLength = sentData.Length;
Stream sendStream = request2.GetRequestStream();
sendStream.Write(sentData, 0, sentData.Length);
sendStream.Close();
HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse();
using (StreamReader stream = new StreamReader(response2.GetResponseStream()))
{
string line;
while ((line = stream.ReadLine()) != null)
textblock.Text += line + "\n";
}
/*foreach (string key in response2.Headers.AllKeys)
{
textblock.Text += key + ": " + response2.Headers[key] + "\n";
}*/
}