I'm looking at HttpURLConnection
, existing since JDK 1.1, 1997 (almost 20 years now), and I'm quite astonished that it's still Java core's official way to create HTTP connections.
Since it was published, many libraries tried to simplify(/upgrade) the usage of an HTTP connections, like Apache's HttpClient.
Other libraries tried to simplify REST HTTP calls, like Jersey.
As far as I could found, no wrapper of HttpURLConnection
was added to the JDK.
Is HttpURLConnection
still Java core's official way to create an HTTP connection?
If not, what's the official way?
The old HttpURLConnection
is currently the standard way to perform HTTP requests in Java SE.
Java EE 7 brought the JAX-RS Client API, which is the standard way to consume REST web services built on top of the HTTP protocol.
And Java SE 9, to be released in 2017, will bring a new HTTP client API that implements HTTP/2 and WebSocket, and can replace the legacy HttpURLConnection
API. The motivation for a new API is described in the JEP 110:
The existing
HttpURLConnection
API and its implementation have numerous problems:
- The base
URLConnection
API was designed with multiple protocols in mind, nearly all of which are now defunct (ftp, gopher, etc.).- The API predates HTTP/1.1 and is too abstract.
- It is hard to use, with many undocumented behaviors.
- It works in blocking mode only (i.e., one thread per request/response).
- It is very hard to maintain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With