This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Sockets and Internet Protocols and the fly likes URLConnection Doubts -- Urgent!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "URLConnection Doubts -- Urgent!!" Watch "URLConnection Doubts -- Urgent!!" New topic
Author

URLConnection Doubts -- Urgent!!

Anshumn Sagar
Greenhorn

Joined: Jun 20, 2001
Posts: 2
Hi,
I have two doubts :
1. I am trying to connect to some site using URLConnection. But I am behind a proxy. How can I do it to connect to that site? In my code I use the following to cross proxy :
System.getProperties().put( "proxySet", "true" );
System.getProperties().put( "proxyHost", "my proxy ip" );
System.getProperties().put( "proxyPort", "8080" );
String password = "username assword";
String encodedPassword = "Base " + new sun.misc.BASE64Encoder().encode( password.getBytes() );
URL url = new URL("http://www.rediff.com");
URLConnection urlConnection = url.openConnection();
urlConnection.setRequestProperty( "Proxy-Authorization", encodedPassword );
urlConnection.setDoOutput(true);
But it does not cross the proxy. Am I doing something wrong in the above piece of code ? Any other way to do it ??
2. Is it possible in JDK 1.1 to make a HTTPS connection ? In the above code I tried, but I get error saying that the protocol is not recognised. Is there any way to do it using jdk 1.1 ?
If not then, any new version of jdk supports HTTPS connection ?
Please give your valuable inputs on the same.
Any help in this shall be highly very helpful for me.
Thanks in advance,
Anshumn
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hello,
Correct me if I'm wrong. It might be as simple as:
String password = "username:password";

Or if that does not work, try to encode your string to bytes using a character set. Default set might not be what you want:
String encodedPassword = new sun.misc.BASE64Encoder().encode( password.getBytes("US-ASCII") );

Java handles HTTPS through the package JSSE which you'll find here:
http://java.sun.com/products/jsse/

Yours
- Lars
Anshumn Sagar
Greenhorn

Joined: Jun 20, 2001
Posts: 2
Hi Lars,
I was trying the same as "username assword";. It is not working. Now I specified the charater set as ("US-ASCII") also, but still it is not crossing the proxy. I am not able to figure out what can be the problem. Please let me know if any other alternative is there.
Thanks for the help..
Anshumn
Originally posted by Lars J. Nilsson:
Hello,
Correct me if I'm wrong. It might be as simple as:
String password = "username assword";

Or if that does not work, try to encode your string to bytes using a character set. Default set might not be what you want:
String encodedPassword = new sun.misc.BASE64Encoder().encode( password.getBytes("US-ASCII") );

Java handles HTTPS through the package JSSE which you'll find here:
http://java.sun.com/products/jsse/

Yours
- Lars

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: URLConnection Doubts -- Urgent!!