Guest User

Untitled

a guest
Oct 9th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. package com.kirdow.enhancewynn;
  2.  
  3. import java.io.DataOutputStream;
  4. import java.net.HttpURLConnection;
  5.  
  6. public class PlayerList
  7. {
  8.   public PlayerList() {}
  9.  
  10.   public static boolean testPlayer(String tag)
  11.   {
  12.     try
  13.     {
  14.       return postRequest(tag).equals("true");
  15.     }
  16.     catch (java.io.IOException localIOException) {}
  17.     return false;
  18.   }
  19.  
  20.   private static String postRequest(String tag) throws java.io.IOException {
  21.     String url = "http://kirdow.com/WynncraftEnhanced/playerlist.php";
  22.     java.net.URL obj = new java.net.URL(url);
  23.     HttpURLConnection con = (HttpURLConnection)obj.openConnection();
  24.    
  25.     con.setRequestMethod("POST");
  26.     con.setRequestProperty("User-Agent", System.getProperty("java.version"));
  27.    
  28.     String urlParameters = "tag=" + tag;
  29.     System.out.println(urlParameters);
  30.    
  31.     con.setDoOutput(true);
  32.     con.setDoInput(true);
  33.     DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  34.     wr.writeBytes(urlParameters);
  35.     wr.flush();
  36.     wr.close();
  37.    
  38.     int responseCode = con.getResponseCode();
  39.    
  40.     if (responseCode != 200) { return "false";
  41.     }
  42.     java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(con.getInputStream()));
  43.    
  44.  
  45.     StringBuffer response = new StringBuffer();
  46.     String inputLine;
  47.     while ((inputLine = in.readLine()) != null) {
  48.       response.append(inputLine);
  49.     }
  50.     in.close();
  51.    
  52.     String ret = response.toString().trim();
  53.     System.out.println(ret.length() + ":" + ret);
  54.     return ret;
  55.   }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment