Example #1
0
 private static String downloadPage(final String url, final String referer) {
   try {
     final HttpURLConnection con = HttpClient.getHttpConnection(new URL(url));
     if (referer != null && !referer.isEmpty()) con.addRequestProperty("Referer", referer);
     return HttpClient.downloadAsString(con);
   } catch (final IOException e) {
     e.printStackTrace();
     return "";
   }
 }
Example #2
0
 public static boolean login(final String user, final String pass) {
   if (user == null || user.length() == 0) {
     if (new File(Configuration.Paths.getServiceKey()).delete())
       log.info("Successfully logged out of services.");
     return false;
   }
   try {
     final URL source =
         new URL(
             Configuration.Paths.URLs.SERVICELOGIN
                 + "?u="
                 + URLEncoder.encode(user, "UTF-8")
                 + "&p="
                 + URLEncoder.encode(pass, "UTF-8"));
     final String key = HttpClient.downloadAsString(source);
     if (key == null || key.length() == 0) {
       log.warning("Invalid service username or password!");
       return false;
     }
     final BufferedWriter out =
         new BufferedWriter(new FileWriter(Configuration.Paths.getServiceKey()));
     out.write(key);
     out.close();
     log.info("Successfully logged into services.");
     return true;
   } catch (final IOException ignored) {
     log.warning("Unable to log into services.");
     return false;
   }
 }