C# 成功登录后,继续重定向到登录页面

C# 成功登录后,继续重定向到登录页面,c#,.net,C#,.net,我尝试在登录后将程序重定向到“”页,但一直将我重定向到登录页 我试过了 request.AllowAutoRedirect = true; 并使用登录cookie进入请求重定向但不工作 问题是在登录了一组cookies后,我不知道如何将其注入重定向请求&我正在使用winformapp ASCIIEncoding encoding = new ASCIIEncoding(); string postData = "login=" + userna

我尝试在登录后将程序重定向到“”页,但一直将我重定向到登录页 我试过了

 request.AllowAutoRedirect = true;
并使用登录cookie进入请求重定向但不工作 问题是在登录了一组cookies后,我不知道如何将其注入重定向请求&我正在使用winformapp

            ASCIIEncoding encoding = new ASCIIEncoding();
            string postData = "login=" + username + "&password=" + pw +"&op=login";
            byte[] data = encoding.GetBytes(postData);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://login.uptobox.com/logarithme");
            request.Method = "POST";
            CookieContainer mycoockie = new CookieContainer();
            request.CookieContainer = mycoockie;
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;
            Stream stream = request.GetRequestStream();
            stream.Write(data, 0, data.Length);
            stream.Close();
            WebResponse response = request.GetResponse();
            stream = response.GetResponseStream();
            StreamReader sr = new StreamReader(stream);
            string source_code = sr.ReadToEnd();

答案是:将成功登录时在标头响应中生成的集cookie添加到新请求

request.Headers.Add("cookie", "value");

你试过context.Redirect吗?我没有使用asp.net