Many people talk to me that HttpURLConnection is based on okhttp from android 4.4 on.
But when I dive into codes of okhttp, the OkHttpURLConnection is a subclass extended from HttpURLConnection.
So, okhttp is based on HttpURLConnection or HttpURLConnection is based on okhttp?
And I find that HttpURLConnection's implement come from rt.jar which is from jdk.
I hope someone can tell me the real relation between okhttp and HttpURLConnection
And I find that HttpURLConnection's implement come from rt.jar which is from jdk.
No. Android does not use rt.jar, at compile time or at runtime.
okhttp is based on HttpURLConnection or HttpURLConnection is based on okhttp?
Android's concrete implementation of the abstract class named HttpURLConnection is based on a fork of OkHttp, as of Android 4.4.
HttpURLConnection itself is not tied to OkHttp; HttpURLConnection existed before Google or Square did. But HttpURLConnection is an abstract class — it is useless on its own. A Java runtime library needs a concrete implementation of HttpURLConnection, which it can then use to implement methods like openConnection() on URL, which needs to return some HttpURLConnection implementation.
FWIW, in Android 4.3 and older, the concrete implementation of HttpURLConnection, AFAIK, was based on the Apache Harmony implementation, the way that most java.* and javax.* classes in Android were.
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