2017-02-19 16 views
0

我試圖重定向我的程序登錄,但保持重定向我 登錄頁面後「https://uptobox.com/?op=my_account」頁面,我試圖成功登錄後不斷重定向到登錄頁面

request.AllowAutoRedirect = true; 

,並使用登錄的Cookie到重定向但不工作 登錄後在標題中產生的問題,一組餅乾我不知道如何來注入到重定向請求&我使用取勝的形式應用的要求

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

您是否嘗試過context.Redirect? – Svek

+0

我不使用asp.net –

回答

0

答案是:將成功登錄的頭響應中生成的set-cookies添加到新請求中。

request.Headers.Add("cookie", "value"); 
相關問題