我正在尝试使用 c# 登录一个网站,我成功通过发送用户名和密码登录,我还打开了请求的自动重定向属性,但网络服务器需要 2 次重定向才能进入欢迎页面,但在我的代码中它只能重定向一次。如何获得最终的定向页面?任何帮助,将不胜感激。
HttpWebRequest request =(HttpWebRequest)WebRequest.Create("http://website.com/client/patronlogin.loginpageform/DEFAULT");
request.AllowAutoRedirect = true; // IMPORTANT
request.Method = "POST";
int pass = sfsdf1;
int no = dsfsdfdf0;
String formContent = "t%3Aac=%24002f%24002ftreblead.com%24002fclient%24002fdefault%24002fsearch%24002faccount%24003f&t%3Aformdata=H4sIAAAAAAAAAJWQv0oDQRDGx4NAMJ1gEURstN2zMI02BkEQDgkc1mFvb7xs2Ntdd%2FZMbKx8CRufQKz0CVLY%2BQ4%2BgI2FlYV7J6Lg%2F274mJnv932XD9CarMAyIXdiFA%2B4d0YnppB6czysCJ3mJZKDnnEF45aLETLPLZJ3Jz0mjEMlM5ZxQtbPgsiF35Wo8tUUfWXXDmad%2B8Xb5wjmEugIo8N3tR8%2BelhIxvyYx4rrIk69k7rYmloP8%2B%2Buf8Hq%2Fxdr4IxAorTKSkkkjZ5d5RuHTxd3EcDUfmtpOdHEuJyO4BSgwXyTfr2pT1qTJeh%2BsUU1hw9Btn8MIkxpjUbtiTXk%2FnOO8%2FSxe3N9thNBlEBbKBm29xrvunpUWAahrr6R6qrbr%2BbD9Q%2FjCx9ggTUPAgAA&j_username="+no.ToString()+"&j_password="+pass.ToString();
byte[] byteArray = Encoding.UTF8.GetBytes(formContent);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
// Get the response ...
WebResponse response;
response = (HttpWebResponse)request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
richTextBox1.AppendText(reader.ReadToEnd());
richTextBox1.AppendText(HttpUtility.UrlDecode(reader.ReadToEnd()));
reader.Close();
dataStream.Close();
response.Close();