Advertisement
Guest User

Untitled

a guest
Mar 1st, 2011
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. import java.net.*;
  2. import java.io.*;
  3.  
  4. public class Login {
  5.  
  6.     private static URL URLObj;
  7.     private static URLConnection connect;
  8.    
  9.     public static void main(String[] args) {
  10.         try {
  11.            
  12.             URLObj = new URL("http://www.hackthissite.org/user/login");
  13.             connect = URLObj.openConnection();
  14.         connect.addRequestProperty("REFERER", "http://www.hackthissite.org");  
  15.             connect.setDoOutput(true);
  16.            
  17.         }
  18.         catch (MalformedURLException ex) {
  19.             System.out.println("The URL specified was unable to be parsed or uses an invalid protocol. Please try again.");
  20.             System.exit(1);
  21.         }
  22.         catch (Exception ex) {
  23.             System.out.println("An exception occurred. " + ex.getMessage());
  24.             System.exit(1);
  25.         }
  26.        
  27.         try {
  28.             BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connect.getOutputStream()));
  29.             writer.write("username=BrandonHeat&password=**********&btn_submit=Login");
  30.             writer.close();
  31.  
  32.             BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream()));
  33.            
  34.             String lineRead = "";
  35.            
  36.             while ((lineRead = reader.readLine()) != null) {
  37.                 System.out.println(lineRead);
  38.             }
  39.            
  40.             reader.close();
  41.         }
  42.         catch (Exception ex) {
  43.             System.out.println("There was an error reading or writing to the URL: " + ex.getMessage());
  44.         }
  45.        
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement