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
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
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");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.