Advertisement
Guest User

Untitled

a guest
May 12th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. private string login(string url, string username, string password)
  2.         {
  3.             HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
  4.             //string cookie = "";
  5.             string values = "vb_login_username=" + username + "&vb_login_password=" + password
  6.                                                     + "&securitytoken=guest&"
  7.                                                     + "cookieuser=checked&"
  8.                                                     + "do=login";
  9.             req.Method = "POST";
  10.             req.ContentType = "application/x-www-form-urlencoded";
  11.             req.ContentLength = values.Length;
  12.             req.Timeout = 10000;
  13.             req.KeepAlive = true;
  14.  
  15.             CookieContainer a = new CookieContainer();
  16.             req.CookieContainer = a;
  17.  
  18.             System.Net.ServicePointManager.Expect100Continue = false; // prevents 417 error
  19.  
  20.             using (StreamWriter writer = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII))
  21.             { writer.Write(values); }
  22.  
  23.             //HttpWebResponse c = (HttpWebResponse)req.GetResponse();
  24.             try { this.response = (HttpWebResponse)req.GetResponse(); }
  25.            
  26.             catch (WebException ex)
  27.             {
  28.  
  29.                 MessageBox.Show(ex.ToString());
  30.             }
  31.  
  32.             foreach (Cookie cook in this.response.Cookies) { this.cookie = this.cookie + cook.ToString() + ";"; }
  33.            
  34.  
  35.             return this.cookie;
  36.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement