What is the difference between URLConnection
, HttpURLConnection
and HttpsURLConnection
(with SSL). Under what conditions, which one should I use?
Asked
Active
Viewed 4.0k times
41

Stevoisiak
- 23,794
- 27
- 122
- 225

Questions
- 20,055
- 29
- 72
- 101
2 Answers
68
URLConnection
is the base class.
HttpURLConnection
is a derived class which you can use when you need the extra API and you are dealing with HTTP or HTTPS only.
HttpsURLConnection
is a 'more derived' class which you can use when you need the 'more extra' API and you are dealing with HTTPS only.
All three of them are abstract, and implemented by specific classes you aren't privy to.

Stevoisiak
- 23,794
- 27
- 122
- 225

user207421
- 305,947
- 44
- 307
- 483
-
1HttpsURLConnection derives from HttpURLConnction not URLConnection directly. – J888 Jun 21 '14 at 04:24
-
5@J888 That's what I meant by 'more derived'. – user207421 Aug 14 '14 at 06:17
8
URLConnection is an abstract class so, you could never instantiate an object of that type.
HttpURLConnection extends URLConnection and provides fields and methods specific to an HTTP URL, such as, HTTP_CLIENT_TIMEOUT or setRequestMethod.
HttpsURLConnection extends HttpURLConnection and provides fields and methods specific to an HTTPS URL.

Owen
- 22,247
- 13
- 42
- 47