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:
SslSocketClient.java - SSL Socket Client Example
How to write an SSL socket client code to communicate to a HTTPS Website using jsse.jar?
✍: FYIcenter
If you want to write an SSL socket client code to communicate to a HTTPS Website using jsse.jar,
you can following the example below:
// Copyright (c) FYIcenter.com
import java.net.*;
import java.io.*;
import javax.net.ssl.*;
public class SslSocketClient {
public static void main(String[] args) throws Exception {
String host = "www.oracle.com";
SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket)factory.createSocket(host, 443);
socket.startHandshake();
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())));
out.println("GET http://"+host+"/index.html HTTP/1.1");
out.println();
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
String line;
int i = 0;
while ((line=in.readLine())!=null && i<10) {
System.out.println(line);
i++;
}
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 SslSocketClient.java \fyicenter>\local\jdk-1.8.0\bin\java SslSocketClient HTTP/1.1 200 OK Server: Oracle-Application-Server-11g Last-Modified: Sun, 24 Jun 2017 18:03:50 GMT device_type: Any host_service: FutureTenseContentServer:11.1.1.8.0 X-Powered-By: Servlet/2.5 JSP/2.1 Content-Language: en-US Content-Type: text/html; charset=UTF-8 X-Frame-Options: SAMEORIGIN Content-Length: 42129
⇒ SslSocketInfo.java - SSL Socket Information
⇐ GetServerCertificate.java - Get Server Certificate
2018-03-31, ∼2932🔥, 0💬
Popular Posts:
Where to get the Java source code for Connector/J 8.0 Core API module? Java source code files for Co...
JDK 11 java.sql.rowset.jmod is the JMOD file for JDK 11 SQL Rowset module. JDK 11 SQL Rowset module ...
Rhino JavaScript Java Library is an open-source implementation of JavaScript written entirely in Jav...
JDK 11 jdk.localedata.jmod is the JMOD file for JDK 11 Localedata module. JDK 11 Locale Data module ...
Apache BCEL Source Code Files are inside the Apache BCEL source package file like bcel-6.6.1-src.zip...