Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

URLConnection Doubts -- Urgent!!

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic