Advertisement
Guest User

Untitled

a guest
Dec 31st, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Windows.Forms;
  4. using System.Net;
  5. using System.IO;
  6. using System.Diagnostics;
  7.  
  8. namespace MagtiFun_Test
  9. {
  10.     public partial class MagtiFun_frm : Form
  11.     {
  12.         public MagtiFun_frm()
  13.         {
  14.             InitializeComponent();
  15.         }
  16.  
  17.         private void login_btn_Click(object sender, EventArgs e)
  18.         {
  19.             string post_data = "&act=1&user=" + usrname_txt.Text + "&password=" + pass_txt.Text;
  20.             string uri = "http://www.magtifun.ge/index.php?page=11&lang=ge";
  21.             //string csrf_token;
  22.  
  23.             HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
  24.             HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
  25.  
  26.             req.KeepAlive = false;
  27.             req.ProtocolVersion = HttpVersion.Version10;
  28.             req.Method = "POST";
  29.             //csrf_token = resp.Headers["set-cookie"] + post_data;
  30.             //WebHeaderCollection header = resp.Headers;
  31.  
  32.             byte[] postByte = Encoding.ASCII.GetBytes(post_data);
  33.  
  34.             req.ContentType = "application/x-www-form-urlencoded";
  35.             req.ContentLength = postByte.Length; //error here
  36.  
  37.             Stream reqStream = req.GetRequestStream();
  38.  
  39.             reqStream.Write(postByte, 0, postByte.Length);
  40.             reqStream.Close();
  41.          
  42.             using (StreamReader file = new StreamReader(resp.GetResponseStream(),Encoding.UTF8))
  43.             {
  44.                 //just to see the response code
  45.                 File.AppendAllText(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\test.txt", file.ReadToEnd());
  46.             }
  47.             //Process.Start("firefox.exe", Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+"\\test.txt");
  48.             MessageBox.Show(resp.StatusCode.ToString()); //shows "OK" even when not logged in
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement