URLConnection problem

Reply

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 Quick reply to this message  
Join Date: Dec 2004
Posts: 4,118
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 471
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: URLConnection problem

 
0
  #2
Oct 24th, 2007
I consider rude to come here and ask for help on project for illigal activities.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC