简体   繁体   English

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

[英]after successful login keep redirecting to login page

i'm trying to redirect my program to " https://uptobox.com/?op=my_account " page after logging in but keep redirecting me to the login page i tried 登录后我试图将程序重定向到“ https://uptobox.com/?op=my_account ”页面,但始终将我重定向到我尝试过的登录页面

 request.AllowAutoRedirect = true;

and using the login cookies into the request of redirecting but not working the problem is after login a set-cookies generated in the header i don't know how to inject that into the redirecting request & i'm using win form app 并使用登录cookie进入重定向请求但不起作用,问题是登录后在标头中生成的set-cookies,我不知道如何将其注入到重定向请求中&我正在使用win form应用

            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();

答案是:将成功登录后的标头响应中生成的set-cookies添加到新请求中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM