Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1.  public void SubmitData()
  2.         {
  3.             try
  4.             {
  5.                 string user = textBox1.Text;
  6.                 string pass = textBox2.Text;
  7.  
  8.                 ASCIIEncoding encoding = new ASCIIEncoding();
  9.                 string postData = "username=" + user + "&password=" + pass + "&remember=remember&submit=&_jafo%5BactiveExperiments%5D=%5B%5D&_jafo%5BexperimentData%5D=%7B%7D";
  10.                 byte[] data = encoding.GetBytes(postData);
  11.  
  12.                 string pageContent = null;
  13.  
  14.                 WebRequest request = WebRequest.Create("https://imgur.com/signin");
  15.                 HttpWebResponse myres = (HttpWebResponse)request.GetResponse();
  16.                 request.Method = "POST";
  17.                 request.ContentType = "application/x-www-form-urlencoded";
  18.                 request.ContentLength = data.Length;
  19.  
  20.                 Stream stream = request.GetRequestStream();
  21.                 stream.Write(data, 0, data.Length);
  22.                 stream.Close();
  23.                
  24.                 WebResponse response = request.GetResponse();
  25.                 stream = response.GetResponseStream();
  26.  
  27.                 StreamReader sr = new StreamReader(stream);
  28.  
  29.                 string final_reponse = sr.ReadToEnd();
  30.  
  31.                 using (StreamReader sr2 = new StreamReader(myres.GetResponseStream()));
  32.                 {
  33.                     pageContent = this.ReadToEnd();
  34.                 }
  35.  
  36.                 if (pageContent.Contains("logout"))
  37.                 {
  38.                     MessageBox.Show("Successful Login");
  39.                 }
  40.  
  41.  
  42.                 //Regex r = new Regex(@"Your login information was incorrect.");
  43.                 //Match m = r.Match(final_reponse);
  44.  
  45.                 //Regex r2 = new Regex(@"logout");
  46.                 //Match m2 = r2.Match(final_reponse);
  47.  
  48.                 //MessageBox.Show(m.Value);
  49.                                    
  50.                     sr.Close();
  51.                 stream.Close();
  52.             }
  53.             catch (Exception ex)
  54.             {
  55.                 MessageBox.Show("Error: " + ex.Message);
  56.             }
  57.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement