Date Archives July 21, 2016

HttpURLConnection vs. HttpsURLConnection

java.net.HttpURLConnection

  • A URLConnection with support for HTTP-specific features
  • It can cover Https addresses also, because HttpsURLConnection extends this.
URL url = new URL("https://www.google.com/");

// HttpURLConnection can cover https URL.openconnection()
// because, HttpsURLConnection extends HttpURLConnection.
HttpURLConnection urlconnection = (HttpURLConnection) URL.openConnection();
try{
   Inputstream in  = new BufferdInputStream(urlconnection.getInputStream());
   readstream(in)
}finally{
   urlconnection.disconnect();
}

javax.net.ssl.HttpsURLConnection

  • HttpsURLConnection extends HttpURLConnection with support for https-specific features such as SSL
  • If HttpsURLConnection use same methods in HttpURLConnection(parent class), it super calls the methods from HttpURLConnection.