Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1.  
  2.  
  3. using System;
  4. using System.IO;
  5. using System.Net;
  6. using System.Text;
  7. using UnityEngine;
  8.  
  9. public class JavaLogin : MonoBehaviour
  10. {
  11. /* public static CookieContainer cookieContainer;
  12. public void run()
  13. {
  14. string username = "Storm"; //Username
  15. string password = "m,{_zwxC|d`"; //Encrypted Password
  16. string urlParam = "&username=" + username + "&password=" + password;
  17. byte[] postData = Encoding.UTF8.GetBytes(urlParam);
  18. HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://krator.net/LoginUserTest.php");
  19. cookieContainer = new CookieContainer();
  20. request.Method = "POST";
  21. request.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
  22. using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
  23. {
  24. writer.Write(urlParam);
  25. Debug.Log("Conversion (default): " + Encoding.Default.GetString(postData));
  26. Debug.Log("Conversion (UTF8): " + Encoding.UTF8.GetString(postData));
  27. Debug.Log("Post reached.");
  28. }
  29. using (StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream(), Encoding.UTF8))
  30. {
  31. while (reader.Peek() >= 0)
  32. {
  33. Debug.Log("Web response: " + reader.ReadLine()); // or something...
  34. }
  35. var cookieContainer = new CookieContainer();
  36.  
  37. using (var httpWebResponse = (HttpWebResponse)request.GetResponse())
  38. {
  39. using (var streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
  40. {
  41. foreach (Cookie cookie in httpWebResponse.Cookies)
  42. {
  43. cookieContainer.Add(cookie);
  44. }
  45. }
  46. return cookieContainer;
  47. }
  48. }
  49. }*/
  50.  
  51. public void run()
  52. {
  53. Login();
  54. ConfirmLogin.Run();
  55. }
  56. protected static CookieContainer Login()
  57. {
  58. string username = "Storm"; //Username
  59. string password = "m,{_zwxC|d`"; //Encrypted Password
  60.  
  61. ASCIIEncoding encoding = new ASCIIEncoding();
  62. string postData = "&username=" + username + "&password=" + password;
  63. byte[] postDataBytes = encoding.GetBytes(postData);
  64.  
  65. HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://www.krator.net/LoginUserTest.php");
  66.  
  67. httpWebRequest.Method = "POST";
  68. httpWebRequest.ContentType = "application/x-www-form-urlencoded";
  69. httpWebRequest.ContentLength = postDataBytes.Length;
  70. httpWebRequest.AllowAutoRedirect = false;
  71.  
  72. using (StreamWriter writer = new StreamWriter(httpWebRequest.GetRequestStream()))
  73. {
  74. writer.Write(postData);
  75. writer.Flush();
  76. writer.Close();
  77. }
  78. using (StreamReader reader = new StreamReader(httpWebRequest.GetResponse().GetResponseStream()))
  79. {
  80. while (reader.Peek() >= 0)
  81. {
  82. Debug.Log("Web response: " + reader.ReadLine()); // or something...
  83. }
  84.  
  85. var cookieContainer = new CookieContainer();
  86.  
  87. using (var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse())
  88. {
  89. using (var streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
  90. {
  91. foreach (Cookie cookie in httpWebResponse.Cookies)
  92. {
  93. cookieContainer.Add(cookie);
  94. }
  95. }
  96. }
  97. return cookieContainer;
  98. }
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement