G
Guest
Gast
Hallo,
ich habe folgenden Code gefunden, um eine SSL Verbindung zu testen.
Ich möchte die Verbindung für die IP 127.0.0.1 und den Port 443 testen. Muss ich diese Werte noch irgendwo setzen? Wie sieht das Ergebnis einer erfolgreich getesteten Verbindung aus? Bin absoluter Neuling auf diesem Gebiet.
MfG Patrick
ich habe folgenden Code gefunden, um eine SSL Verbindung zu testen.
Code:
public class UseHttps
{
public static void main(String args[])
{
Class factoryClass = null;
URLStreamHandlerFactory factory = null;
String socksServer = "";
String socksPort = "";
String usage = "Usage: java UseHttps URL-to-be-read socksServerName(optional) socksPortNumber(optional)";
if ((args == null) || (args.length == 0))
{
System.out.println(usage);
return;
}
String prefix = "https://";
// Build the complete URL, including the protocol
String fullURL = prefix.concat(args[0]);
if (args.length > 3) {
System.out.println(usage);
return;
}
if (args.length >= 2) {
socksServer = args[1];
if (args.length == 3) {
socksPort = args[2];
}
}
System.out.println("Computed URL is " + fullURL);
// Now either we can rely on the user to have added us to
// the security.provider list in java.security, or we can
// dynamically add ourselves here. We'll set it up here.
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties properties = System.getProperties();
String handlers = System.getProperty("java.protocol.handler.pkgs");
if (handlers == null)
{
// nothing specified yet (expected case)
properties.put("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
}
else
{
// something already there, put ourselves out front
properties.put("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol|".concat(handlers));
}
if (!socksServer.equals(""))
{
// Must do the setup to get to the socks host
// Could check first to see if the user already specified it on the invocation line
if (System.getProperty("socksProxyHost") == null)
{
properties.put("socksProxyHost", socksServer);
}
if (!socksPort.equals(""))
{
if (System.getProperty("socksProxyPort") == null)
{
properties.put("socksProxyPort", socksPort);
}
}
}
System.setProperties(properties); // put the updated properties back in System
try
{
URL page = new URL(fullURL); // Process the URL far enough to find the right handler
URLConnection urlc = page.openConnection();
urlc.setUseCaches(false); // Don't look at possibly cached data
System.out.println("Content-type = " + urlc.getContentType()); // See what's here
System.out.println("Content-length = " + urlc.getContentLength()); // See how much of it there is
// Read it all and print it out
BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
String buffer = "";
while (buffer != null)
{
try
{
System.out.println(buffer);
buffer = br.readLine();
}
catch (IOException ioe)
{
ioe.printStackTrace();
break;
}
}
}
catch (MalformedURLException mue)
{
System.out.println(fullURL + " is not a URL that can be resolved");
}
catch (IOException ie)
{
ie.printStackTrace();
}
}
}
Ich möchte die Verbindung für die IP 127.0.0.1 und den Port 443 testen. Muss ich diese Werte noch irgendwo setzen? Wie sieht das Ergebnis einer erfolgreich getesteten Verbindung aus? Bin absoluter Neuling auf diesem Gebiet.
MfG Patrick