Advertisement
Guest User

Untitled

a guest
Jun 1st, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. public static String checkCredentials(List<String> credentials) {
  2.         Log.d(TAG, "In checkCredentials");
  3.         Log.d(TAG,"Credentials are "+credentials.toString());
  4.         String user_name = credentials.get(0);
  5.         Log.d(TAG, "user_name is "+user_name);
  6.         String user_password = credentials.get(1);
  7.         String httpsURL = "https://willbeddow.com/auth.cgi";
  8.         String charset = "UTF-8";
  9.         String param1 = user_name;
  10.         String param2 = user_password;
  11.         String query = "user=" + encode(user_name);
  12.         query += "&";
  13.         query += "password=" + encode(user_password);
  14.         Log.d(TAG, "Finished formatting url, HttpsURL is "+httpsURL);
  15.         try{
  16.             URL myurl = new URL(httpsURL);
  17.             HttpsURLConnection con = (HttpsURLConnection) myurl.openConnection();
  18.             con.setRequestMethod("POST");
  19.  
  20.             con.setRequestProperty("Content-length", valueOf(query.length()));
  21.             con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  22.             con.setDoOutput(true);
  23.             con.setDoInput(true);
  24.  
  25.             DataOutputStream output = new DataOutputStream(con.getOutputStream());
  26.  
  27.  
  28.             output.writeBytes(query);
  29.  
  30.             output.close();
  31.  
  32.             DataInputStream input = new DataInputStream(con.getInputStream());
  33.  
  34.  
  35.             for (int c = input.read(); c != -1; c = input.read())
  36.                 System.out.print((char) c);
  37.             input.close();
  38.  
  39.             Log.d(TAG, "Resp Code:"+con .getResponseCode());
  40.             Log.d(TAG, System.out.println("Resp Message:"+ con .getResponseMessage());
  41.             return con.getResponseMessage();
  42.         }
  43.         catch (Exception m){
  44.             Log.d(TAG, "Exception "+m.toString()+" occurred. URL was: "+httpsURL.toString());
  45.             return "Exception";
  46.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement