import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.SSLSocket;import com.sun.net.ssl.SSLContext;
import com.sun.net.ssl.TrustManager;
import com.sun.net.ssl.X509TrustManager;import java.net.URL;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Properties;
import java.io.IOException;
import java.io.*;
import java.net.MalformedURLException;
import javax.net.ssl.HandshakeCompletedEvent;
import javax.net.ssl.HandshakeCompletedListener;
import java.net.SocketException;
import com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnection;
public class SSLTest { public static void main(String args[])
{ System.setProperty("javax.net.ssl.trustStore", "E://Java//jdk1.5.0_06//jre//lib//jdk-cacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");

SSLSocketFactory factory =(SSLSocketFactory)SSLSocketFactory.getDefault();
SSLSocket socket=null;

try{
 socket =(SSLSocket)factory.createSocket("172.25.73.225", 443);
         System.out.println("Conntion succeed!");
}catch(UnknownHostException e1)
{
System.out.println("Conntion fail 1!");
e1.printStackTrace();
}catch(IOException e2)
{
System.out.println("Conntion fail 2!");
e2.printStackTrace();
}


String getRequest = "GET " + "https://172.25.73.225/GS/Admin/Welcome.asp" + " HTTP/1.1";
String hostSpecification = "Host: " + "172.25.73.225";
System.out.println(getRequest);
System.out.println(hostSpecification);


try
{ PrintWriter out = new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(
socket.getOutputStream())));
out.println(getRequest);
out.println(hostSpecification);
out.println();
out.flush(); if (out.checkError())
System.out.println("SSLSocketClient:  java.io.PrintWriter error"); // read response 

BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream())); String inputLine;
while ((inputLine = in.readLine()) != null)
{
System.out.println(inputLine);

} in.close();
out.close();
socket.close(); }
catch(Exception e)
{
System.out.println("Conntion fail 3!");
e.printStackTrace();
}
}

}
/////////////////////////////////////////////////////////////////////////////
用IE可以打开改网页
但是程序 读出的是
Conntion succeed!
GET https://172.25.73.225/GS/Admin/Welcome.asp HTTP/1.1
Host: 172.25.73.225
HTTP/1.1 302 Object moved
Server: Microsoft-IIS/5.0
Date: Fri, 29 Sep 2006 06:29:21 GMT
X-Powered-By: ASP.NET
Location: /GS/Admin/Login.asp
Content-Length: 121
Content-Type: text/html; Charset=utf-8
Expires: Fri, 29 Sep 2006 06:28:21 GMT
Set-Cookie: ASPSESSIONIDQSBABQRS=DGEKHCIAPNNCNEMPJKFBECBO; path=/
Cache-control: private<head><title>Object moved</title></head>
<body><h1>Object Moved</h1>This object may be found <a HREF="">here</a>.</body>
Conntion fail 3!并且有异常
java.net.SocketException: Connection reset是什么原因