943,929 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 5369
  • Java RSS
Oct 24th, 2007
0

URLConnection problem

Expand Post »
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:

JAVA Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
claudiu_is is offline Offline
40 posts
since Jul 2007
Oct 24th, 2007
0

Re: URLConnection problem

I consider rude to come here and ask for help on project for illigal activities.
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 873
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: J2me
Next Thread in Java Forum Timeline: Storing Objects





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC