• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

going mad about HttpsURLConnection

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there ,

maybe there are thousands of similar postings in that forum,
or maybe there are millions of great tutorials about it on the
internet. As far as it concerns me, I found loads of very
abstract papers about that ssl stuff, but much to abstruse
for a newb like me. So here's my problem:
There's a https server I want to connect to with my Java application.
All I have is the server's IP, port, a keystore with client
trusted certificates and a password. That's it.
I'm sure, there has to be a way to connect to that stupid server, but since now I didn't find a way. Would you please be so kind to help me out of that problem? I'm really loosing hope
Thanx in advance ...
- Thomas -
[ September 25, 2003: Message edited by: Thomas Rochon ]
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Thomas,
try:
System.setProperty("javax.net.ssl.trustStore","mykeystore");
System.setProperty("javax.net.ssl.trustStorePassword", "123456");
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket client = (SSLSocket) factory.createSocket(host, port);
DataInput in = new DataInputStream(client.getInputStream());
PrintStream out = new PrintStream(client.getOutputStream());
out.println("ClientMessage");
String response = in.readLine();
System.out.println(response);
client.close();
HTH
Torsten
 
Torsten Schippel
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry,
with HttpsURLConnection:
System.setProperty("javax.net.ssl.trustStore","mykeystore");
System.setProperty("javax.net.ssl.trustStorePassword", "123456");
URL url = new URL("https://127.0.0.1:443/");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
 
Thomas Rochon
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Torsten !
Cant believe it's that simple. But it works !
Your small code snippet helped me out of a lot of trouble.
Thanx ! Thanx a lot !
Best regards,
- Thomas -
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic