Social Icons

twitterfacebookgoogle pluslinkedinrss feed

Tuesday, February 22, 2011

Java HTTPS Client

Here is example for a Java HTTPS client


import java.net.URL;
import java.io.*;
import javax.net.ssl.HttpsURLConnection;

public class HttpsClient{
  public static void main(String[] args) throws Exception{
    String httpsURL = "https://encrypted.google.com/";
    URL myurl = new URL(httpsURL);
    HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
    InputStream ins = con.getInputStream();
    InputStreamReader isr = new InputStreamReader(ins);
    BufferedReader in = new BufferedReader(isr);

    String inputLine;

    while ((inputLine = in.readLine()) != null) {
      System.out.println(inputLine);
    }

    in.close();
  }
}