Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relation between okhttp and HttpURLConnection

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

like image 892
QuinnChen Avatar asked Nov 08 '25 23:11

QuinnChen


1 Answers

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.

like image 137
CommonsWare Avatar answered Nov 10 '25 12:11

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!