I\'m working on a project where I\'m creating a class to run http client requests (my class acts as a client). It takes in a url and a request method (GET, POST, PUT, etc)
since HttpsURLConnection extends HttpURLConnection you can declare conn as HttpsURLConnection. In this way you can access the common interface (setRequestMethod()).
In order to access the extension methods (like getCipherSuite(), defined only in the child class HttpsURLConnection) you must use a cast after an instanceof:
if (conn instanceof HttpsURLConnection) {
HttpsURLConnection secured = (HttpsURLConnection) conn;
String cipher = secured.getCipherSuite();
}
HttpsURLConnection extends HttpUrlConnection, so you do not need the HttpsUrlConnection, you can just do
HttpURLConnection conn = (HttpURLConnection) url.openConnection();