can't get SSLSocketFactory to produce socket which can connect to https

Ben Flaumenhaft (benf@bearriver.com)
Mon, 25 Jan 1999 13:30:13 -0800

Hello:

I've been trying to connect to an https web server. According to numerous
documentation, the standard URL package supports https. It turns out this
isn't true.

I'm now trying to use the javax.net.ssl.* classes to connect using https.
I'm using SSLSocketFactory to get a Socket, connecting to port 443, sending
a GET request, and trying to read in the results -- but it just hangs. I'm
using the standard javax.net packages and JDK 1.2.

This is straightforward code, and all the Q&A postings suggest that this
should work. I've attached the code; can you tell me what's going on?

Thanks,
Ben Flaumenhaft

import java.io.*;
import java.net.*;
import javax.net.*;
import javax.net.ssl.*;

public class ssl
{
public static void
main (String [] inArgs)
{
try
{
SocketFactory factory = SSLSocketFactory.getDefault ();

Socket s = factory.createSocket ("payments.internic.net", 443);

// send get request

PrintWriter sout = new PrintWriter (s.getOutputStream ());

sout.println ("GET / HTTP/1.0");
sout.println ("");

// read result

DataInputStream sin = new DataInputStream (s.getInputStream ());

while (true)
{
System.out.print(" reading: " );
String line = sin.readLine ();
if (line == null ) // || line.length () == 0)
break;

System.out.println (line);
}
}
catch (Exception e)
{
e.printStackTrace ();
}
}

}