Categories:
Audio (13)
Biotech (29)
Bytecode (35)
Database (77)
Framework (7)
Game (7)
General (512)
Graphics (53)
I/O (32)
IDE (2)
JAR Tools (86)
JavaBeans (16)
JDBC (89)
JDK (337)
JSP (20)
Logging (103)
Mail (54)
Messaging (8)
Network (71)
PDF (94)
Report (7)
Scripting (83)
Security (32)
Server (119)
Servlet (17)
SOAP (24)
Testing (50)
Web (19)
XML (301)
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
Â
2018-03-31, 1576👍, 0💬
Popular Posts:
What Is commons-net-ftp-2.0.jar? commons-net-ftp-2.0.jar is the JAR file for Apache Commons Net FTP ...
The Web Services Description Language for Java Toolkit (WSDL4J), Release 1.6.2, allows the creation,...
maven-core-3.5.4.jar is the JAR file for Apache Maven 3.5.4 Core module. Apache Maven is a software ...
The SOAP with Attachments API for JavaTM (SAAJ) 1.3 provides the API for creating and sending SOAP m...
Apache Axis2 is the core engine for Web services. It is a complete re-design and re-write of the wid...