Skip to content

Instantly share code, notes, and snippets.

@josacar
Last active November 30, 2017 20:42
Show Gist options
  • Save josacar/cad7ed0ebaf8555011bdd592332b9f69 to your computer and use it in GitHub Desktop.
Save josacar/cad7ed0ebaf8555011bdd592332b9f69 to your computer and use it in GitHub Desktop.
import java.net.*;
import java.io.*;
import javax.net.ssl.*;
public class SSLSocketClient {
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.out.println("Usage: "+SSLSocketClient.class.getName() +" <host> <port>");
System.exit(1);
}
try {
SSLSocketFactory factory =
(SSLSocketFactory)SSLSocketFactory.getDefault();
SSLSocket socket =
(SSLSocket)factory.createSocket(args[0], Integer.parseInt(args[1]));
socket.startHandshake();
PrintWriter out = new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(
socket.getOutputStream())));
out.println("GET / HTTP/1.0");
out.println("Host: gateway.flywire.com");
out.println("User-Agent: curl/7.54.0");
out.println("Accept: */*");
out.println();
out.flush();
if (out.checkError())
System.out.println(
"SSLSocketClient: java.io.PrintWriter error");
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) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment