View Single Post
Join Date: Jul 2007
Posts: 31
Reputation: claudiu_is is an unknown quantity at this point 
Solved Threads: 1
claudiu_is's Avatar
claudiu_is claudiu_is is offline Offline
Light Poster

URLConnection problem

 
0
  #1
Oct 24th, 2007
I`m trying to compile a small program for authentication on a torrent site but when it reaches the setRequestProperty() line throws an exception:
Exception in thread "main" java.lang.IllegalStateException: Already connected
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(Unknown Source)
at MovieCrawler.main(MovieCrawler.java:22)
I understand that something is already connected! How can I disconnect before using this method;
here is the code:

  1. import java.net.*;
  2. import java.io.*;
  3.  
  4.  
  5. public class MovieCrawler {
  6. public static void main(String[] args) throws Exception {
  7. URL url = new URL("http://www.torrentleech.org/login.php");
  8. URLConnection uCon = url.openConnection();
  9. BufferedReader in = new BufferedReader(new InputStreamReader(uCon.getInputStream()));
  10.  
  11. String inputLine;
  12. while ((inputLine = in.readLine()) != null)
  13. System.out.println(inputLine);
  14.  
  15. in.close();
  16. //for (int i=0;i<20;i++)
  17. // System.out.println(uCon.getHeaderFieldKey(i)+": "+uCon.getHeaderField(i));
  18. //System.out.println("kaaaaaaaaaaaaaa: "+uCon.getRequestProperty("Cookies"));
  19. String uspass = "***:***";
  20. uCon.setRequestProperty("Authorization","Basic"+uspass);
  21. uCon.connect();
  22. BufferedReader in2 = new BufferedReader(new InputStreamReader(uCon.getInputStream()));
  23. inputLine = "";
  24. while ((inputLine = in2.readLine()) != null)
  25. System.out.println(inputLine);
  26. in2.close();
  27. }
  28. }

pls help, I`ve spent several hours finding/creating an working authentication method... and this is my "greate" result
Reply With Quote