Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
SslClientCmd.java - SSL Client Command Example
How to create an SSL client program to run like a command?
✍: FYIcenter
Here is an SSL client example program you can run like a command to
communicate to any HTTPS web server:
// Copyright (c) FYIcenter.com
import java.net.*;
import java.io.*;
import javax.net.ssl.*;
public class SslClientCmd {
public static void main(String[] args) throws Exception {
String host = "www.oracle.com";
int port = 443;
String url = "http://www.oracle.com/index.html";
if (args.length < 3) {
System.out.println("USAGE: java SslClientCmd host port url");
System.exit(-1);
}
host = args[0];
port = Integer.parseInt(args[1]);
url = args[2];
SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket)factory.createSocket(host, port);
socket.startHandshake();
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())));
out.println("GET "+url+" HTTP/1.1");
out.println();
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
String line = in.readLine();
while (line.length()>0) {
System.out.println(line);
line = in.readLine();
}
in.close();
out.close();
socket.close();
}
}
You can compile and run the above example in a command window:
\fyicenter>\local\jdk-1.8.0\bin\javac SslClientCmd.java \fyicenter>\local\jdk-1.8.0\bin\java SslClientCmd USAGE: java SslClientCmd host port url \fyicenter>\local\jdk-1.8.0\bin\java SslClientCmd www.oracle.com 443 http://www.oracle.com/index.html | more HTTP/1.1 200 OK Server: Oracle-Application-Server-11g Content-Language: en-US Content-Type: text/html; charset=UTF-8 Content-Length: 42129 ... \fyicenter>\local\jdk-1.8.0\bin\java SslClientCmd www.oracle.com 443 http://www.oracle.com/junk.html HTTP/1.1 404 Not Found Server: Oracle-Application-Server-11g Accept-Ranges: bytes Content-Length: 2720 Content-Type: text/html; charset=UTF-8 ...
⇒ Create SSL Server Certificate with "keytool"
⇐ SslCipherList.java - SSL Cipher List
2018-03-31, ∼2891🔥, 0💬
Popular Posts:
commons-net-1.4.1.jar is the JAR file for Apache Commons Net 1.4.1, which implements the client side...
JDK 11 jdk.jshell.jmod is the JMOD file for JDK 11 JShell tool, which can be invoked by the "jshell"...
How to download and install ojdbc5.jar for Oracle 11g R1? ojdbc5.jar for Oracle 11g R1 is a Java 5 J...
What Is poi-examples-5.2.3.jar? poi-examples-5.2.3.jar is one of the JAR files for Apache POI 5.2.3,...
JRE 8 rt.jar is the JAR file for JRE 8 RT (Runtime) libraries. JRE (Java Runtime) 8 is the runtime e...