Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.io.UnsupportedEncodingException;
- import java.util.ArrayList;
- import java.util.List;
- import org.apache.http.HttpEntity;
- import org.apache.http.NameValuePair;
- import org.apache.http.client.ClientProtocolException;
- import org.apache.http.client.entity.UrlEncodedFormEntity;
- import org.apache.http.client.methods.CloseableHttpResponse;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.impl.client.CloseableHttpClient;
- import org.apache.http.impl.client.HttpClients;
- import org.apache.http.message.BasicNameValuePair;
- import org.apache.http.util.EntityUtils;
- import org.json.JSONObject;
- public class Main {
- public static void main(String[] args) {
- String token;
- //System.out.println("TEST Register --------------------");
- //Register reg = new Register("TacoBell", "TacoBell@yahoo", "password");
- //reg.Execute();
- //System.out.println("TEST LOGIN --------------------");
- Login log = new Login("TacoBell", "password");
- token = log.Execute();
- System.out.println(token);
- //System.out.println("TEST GetMessage ---------------");
- //System.out.println("TEST SendMessage -------------------");
- }
- }
- //================================================================================================= Register
- import java.io.IOException;
- import java.io.UnsupportedEncodingException;
- import java.util.ArrayList;
- import java.util.List;
- import org.apache.http.HttpEntity;
- import org.apache.http.NameValuePair;
- import org.apache.http.client.ClientProtocolException;
- import org.apache.http.client.entity.UrlEncodedFormEntity;
- import org.apache.http.client.methods.CloseableHttpResponse;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.impl.client.CloseableHttpClient;
- import org.apache.http.impl.client.HttpClients;
- import org.apache.http.message.BasicNameValuePair;
- import org.apache.http.util.EntityUtils;
- public class Register {
- private CloseableHttpClient httpclient;
- private String username;
- private String email;
- private String password;
- public Register() {
- httpclient = HttpClients.createDefault();
- }
- public Register(String name, String mail, String pass) {
- httpclient = HttpClients.createDefault();
- username = name;
- email = mail;
- password = pass;
- }
- public void Execute() {
- try {
- System.out.println("POST ---");
- HttpPost httpPost = new HttpPost("https://sstssecurity.com/register.php");
- List <NameValuePair> nvps = new ArrayList <NameValuePair>();
- nvps.add(new BasicNameValuePair("username", username));
- nvps.add(new BasicNameValuePair("email", email));
- nvps.add(new BasicNameValuePair("password", password));
- httpPost.setEntity(new UrlEncodedFormEntity(nvps));
- CloseableHttpResponse response2 = httpclient.execute(httpPost);
- System.out.println(response2.getStatusLine());
- HttpEntity entity2 = response2.getEntity();
- // do something useful with the response body
- // and ensure it is fully consumed
- //EntityUtils.consume(entity2);
- System.out.println(EntityUtils.toString(entity2));
- response2.close();
- } catch(IOException e) {
- System.out.println("IOException");
- }
- }
- }
- //================================================================================================= LOGIN
- import java.io.IOException;
- import java.io.UnsupportedEncodingException;
- import java.util.ArrayList;
- import java.util.List;
- import org.apache.http.HttpEntity;
- import org.apache.http.NameValuePair;
- import org.apache.http.client.ClientProtocolException;
- import org.apache.http.client.entity.UrlEncodedFormEntity;
- import org.apache.http.client.methods.CloseableHttpResponse;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.impl.client.CloseableHttpClient;
- import org.apache.http.impl.client.HttpClients;
- import org.apache.http.message.BasicNameValuePair;
- import org.apache.http.util.EntityUtils;
- public class Login {
- private CloseableHttpClient httpclient;
- private String username;
- private String password;
- public Login() {
- httpclient = HttpClients.createDefault();
- }
- public Login(String name, String pass) {
- httpclient = HttpClients.createDefault();
- username = name;
- password = pass;
- }
- public String Execute() {
- String token = "";
- try {
- System.out.println("POST ---");
- HttpPost httpPost = new HttpPost("https://sstssecurity.com/login.php");
- List <NameValuePair> nvps = new ArrayList <NameValuePair>();
- nvps.add(new BasicNameValuePair("username", username));
- nvps.add(new BasicNameValuePair("password", password));
- httpPost.setEntity(new UrlEncodedFormEntity(nvps));
- CloseableHttpResponse response2 = httpclient.execute(httpPost);
- System.out.println(response2.getStatusLine());
- HttpEntity entity2 = response2.getEntity();
- // do something useful with the response body
- // and ensure it is fully consumed
- //EntityUtils.consume(entity2);
- //System.out.println(EntityUtils.toString(entity2));
- //System.out.println("GONNA WRITE TO TOKEN ====================");
- token = EntityUtils.toString(entity2);
- //System.out.println("TOKEN IS STORED ====================");
- response2.close();
- } catch(IOException e) {
- System.out.println("IOException");
- }
- return(token);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement