Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.49 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.io.UnsupportedEncodingException;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import org.apache.http.HttpEntity;
  7. import org.apache.http.NameValuePair;
  8. import org.apache.http.client.ClientProtocolException;
  9. import org.apache.http.client.entity.UrlEncodedFormEntity;
  10. import org.apache.http.client.methods.CloseableHttpResponse;
  11. import org.apache.http.client.methods.HttpGet;
  12. import org.apache.http.client.methods.HttpPost;
  13. import org.apache.http.impl.client.CloseableHttpClient;
  14. import org.apache.http.impl.client.HttpClients;
  15. import org.apache.http.message.BasicNameValuePair;
  16. import org.apache.http.util.EntityUtils;
  17. import org.json.JSONObject;
  18.  
  19. public class Main {
  20.  
  21. public static void main(String[] args) {
  22.  
  23. String token;
  24.  
  25. //System.out.println("TEST Register --------------------");
  26.  
  27. //Register reg = new Register("TacoBell", "TacoBell@yahoo", "password");
  28. //reg.Execute();
  29.  
  30.  
  31. //System.out.println("TEST LOGIN --------------------");
  32.  
  33. Login log = new Login("TacoBell", "password");
  34. token = log.Execute();
  35. System.out.println(token);
  36.  
  37. //System.out.println("TEST GetMessage ---------------");
  38.  
  39.  
  40. //System.out.println("TEST SendMessage -------------------");
  41. }
  42.  
  43. }
  44.  
  45.  
  46. //================================================================================================= Register
  47.  
  48. import java.io.IOException;
  49. import java.io.UnsupportedEncodingException;
  50. import java.util.ArrayList;
  51. import java.util.List;
  52.  
  53. import org.apache.http.HttpEntity;
  54. import org.apache.http.NameValuePair;
  55. import org.apache.http.client.ClientProtocolException;
  56. import org.apache.http.client.entity.UrlEncodedFormEntity;
  57. import org.apache.http.client.methods.CloseableHttpResponse;
  58. import org.apache.http.client.methods.HttpGet;
  59. import org.apache.http.client.methods.HttpPost;
  60. import org.apache.http.impl.client.CloseableHttpClient;
  61. import org.apache.http.impl.client.HttpClients;
  62. import org.apache.http.message.BasicNameValuePair;
  63. import org.apache.http.util.EntityUtils;
  64.  
  65. public class Register {
  66.  
  67. private CloseableHttpClient httpclient;
  68. private String username;
  69. private String email;
  70. private String password;
  71.  
  72. public Register() {
  73. httpclient = HttpClients.createDefault();
  74. }
  75.  
  76. public Register(String name, String mail, String pass) {
  77. httpclient = HttpClients.createDefault();
  78. username = name;
  79. email = mail;
  80. password = pass;
  81. }
  82.  
  83. public void Execute() {
  84. try {
  85. System.out.println("POST ---");
  86. HttpPost httpPost = new HttpPost("https://sstssecurity.com/register.php");
  87. List <NameValuePair> nvps = new ArrayList <NameValuePair>();
  88. nvps.add(new BasicNameValuePair("username", username));
  89. nvps.add(new BasicNameValuePair("email", email));
  90. nvps.add(new BasicNameValuePair("password", password));
  91. httpPost.setEntity(new UrlEncodedFormEntity(nvps));
  92. CloseableHttpResponse response2 = httpclient.execute(httpPost);
  93.  
  94. System.out.println(response2.getStatusLine());
  95. HttpEntity entity2 = response2.getEntity();
  96. // do something useful with the response body
  97. // and ensure it is fully consumed
  98. //EntityUtils.consume(entity2);
  99. System.out.println(EntityUtils.toString(entity2));
  100. response2.close();
  101. } catch(IOException e) {
  102. System.out.println("IOException");
  103. }
  104. }
  105. }
  106.  
  107.  
  108. //================================================================================================= LOGIN
  109.  
  110. import java.io.IOException;
  111. import java.io.UnsupportedEncodingException;
  112. import java.util.ArrayList;
  113. import java.util.List;
  114.  
  115. import org.apache.http.HttpEntity;
  116. import org.apache.http.NameValuePair;
  117. import org.apache.http.client.ClientProtocolException;
  118. import org.apache.http.client.entity.UrlEncodedFormEntity;
  119. import org.apache.http.client.methods.CloseableHttpResponse;
  120. import org.apache.http.client.methods.HttpGet;
  121. import org.apache.http.client.methods.HttpPost;
  122. import org.apache.http.impl.client.CloseableHttpClient;
  123. import org.apache.http.impl.client.HttpClients;
  124. import org.apache.http.message.BasicNameValuePair;
  125. import org.apache.http.util.EntityUtils;
  126.  
  127. public class Login {
  128.  
  129. private CloseableHttpClient httpclient;
  130. private String username;
  131. private String password;
  132.  
  133. public Login() {
  134. httpclient = HttpClients.createDefault();
  135. }
  136.  
  137. public Login(String name, String pass) {
  138. httpclient = HttpClients.createDefault();
  139. username = name;
  140. password = pass;
  141. }
  142.  
  143. public String Execute() {
  144. String token = "";
  145.  
  146. try {
  147. System.out.println("POST ---");
  148. HttpPost httpPost = new HttpPost("https://sstssecurity.com/login.php");
  149. List <NameValuePair> nvps = new ArrayList <NameValuePair>();
  150. nvps.add(new BasicNameValuePair("username", username));
  151. nvps.add(new BasicNameValuePair("password", password));
  152. httpPost.setEntity(new UrlEncodedFormEntity(nvps));
  153. CloseableHttpResponse response2 = httpclient.execute(httpPost);
  154.  
  155. System.out.println(response2.getStatusLine());
  156. HttpEntity entity2 = response2.getEntity();
  157. // do something useful with the response body
  158. // and ensure it is fully consumed
  159. //EntityUtils.consume(entity2);
  160. //System.out.println(EntityUtils.toString(entity2));
  161.  
  162. //System.out.println("GONNA WRITE TO TOKEN ====================");
  163. token = EntityUtils.toString(entity2);
  164. //System.out.println("TOKEN IS STORED ====================");
  165. response2.close();
  166. } catch(IOException e) {
  167. System.out.println("IOException");
  168. }
  169.  
  170. return(token);
  171. }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement