Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Net;
- using System.Text;
- using UnityEngine;
- public class JavaLogin : MonoBehaviour
- {
- /* public static CookieContainer cookieContainer;
- public void run()
- {
- string username = "Storm"; //Username
- string password = "m,{_zwxC|d`"; //Encrypted Password
- string urlParam = "&username=" + username + "&password=" + password;
- byte[] postData = Encoding.UTF8.GetBytes(urlParam);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://krator.net/LoginUserTest.php");
- cookieContainer = new CookieContainer();
- request.Method = "POST";
- request.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
- using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
- {
- writer.Write(urlParam);
- Debug.Log("Conversion (default): " + Encoding.Default.GetString(postData));
- Debug.Log("Conversion (UTF8): " + Encoding.UTF8.GetString(postData));
- Debug.Log("Post reached.");
- }
- using (StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream(), Encoding.UTF8))
- {
- while (reader.Peek() >= 0)
- {
- Debug.Log("Web response: " + reader.ReadLine()); // or something...
- }
- var cookieContainer = new CookieContainer();
- using (var httpWebResponse = (HttpWebResponse)request.GetResponse())
- {
- using (var streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
- {
- foreach (Cookie cookie in httpWebResponse.Cookies)
- {
- cookieContainer.Add(cookie);
- }
- }
- return cookieContainer;
- }
- }
- }*/
- public void run()
- {
- Login();
- ConfirmLogin.Run();
- }
- protected static CookieContainer Login()
- {
- string username = "Storm"; //Username
- string password = "m,{_zwxC|d`"; //Encrypted Password
- ASCIIEncoding encoding = new ASCIIEncoding();
- string postData = "&username=" + username + "&password=" + password;
- byte[] postDataBytes = encoding.GetBytes(postData);
- HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://www.krator.net/LoginUserTest.php");
- httpWebRequest.Method = "POST";
- httpWebRequest.ContentType = "application/x-www-form-urlencoded";
- httpWebRequest.ContentLength = postDataBytes.Length;
- httpWebRequest.AllowAutoRedirect = false;
- using (StreamWriter writer = new StreamWriter(httpWebRequest.GetRequestStream()))
- {
- writer.Write(postData);
- writer.Flush();
- writer.Close();
- }
- using (StreamReader reader = new StreamReader(httpWebRequest.GetResponse().GetResponseStream()))
- {
- while (reader.Peek() >= 0)
- {
- Debug.Log("Web response: " + reader.ReadLine()); // or something...
- }
- var cookieContainer = new CookieContainer();
- using (var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse())
- {
- using (var streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
- {
- foreach (Cookie cookie in httpWebResponse.Cookies)
- {
- cookieContainer.Add(cookie);
- }
- }
- }
- return cookieContainer;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement