Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OkHttp 3 and HttpURLConnection

I am a bit confused about how to upgrade OkHttp to v3.0.0 while keeping our code that uses HttpURLConnection. Our current dependencies are:

compile 'com.squareup.okhttp:okhttp:2.7.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.0'

The changelog states:

The Apache HTTP client and HttpURLConnection APIs are deprecated. They continue to work as they always have, but we're moving everything to the new OkHttp 3 API. The okhttp-apache and okhttp-urlconnection modules should be only be used to accelerate a transition to OkHttp's request/response API. These deprecated modules will be dropped in an upcoming OkHttp 3.x release.

Unfortunately it is not clear to me what "we're moving everything to the new OkHttp 3 API" means.

I tried to depend on com.squareup.okhttp:okhttp-urlconnection:3.0.0 but that doesn't exist.

Should I keep com.squareup.okhttp:okhttp-urlconnection:2.7.0 and upgrade only com.squareup.okhttp:okhttp to 3.0.0? Or does this sentence mean that depending only on com.squareup.okhttp:okhttp should work?

like image 764
BoD Avatar asked Jan 14 '16 09:01

BoD


People also ask

Does OkHttp use HttpURLConnection?

The OkHttp library actually provides an implementation of the HttpUrlConnection interface, which Android 4.4 and later versions now use.

What is OkHttp used for?

What is OkHttp? OkHttp is an HTTP client from Square for Java and Android applications. It's designed to load resources faster and save bandwidth. OkHttp is widely used in open-source projects and is the backbone of libraries like Retrofit, Picasso, and many others.

Is OkHttp third party?

OkHttp is a third-party library developed by Square for sending and receive HTTP-based network requests.

What is OkHttp client in Android?

OkHttp is an efficient HTTP & HTTP/2 client for Android and Java applications. It comes with advanced features, such as connection pooling (if HTTP/2 isn't available), transparent GZIP compression, and response caching, to avoid the network completely for repeated requests.


1 Answers

I tried to depend on com.squareup.okhttp:okhttp-urlconnection:3.0.0 but that doesn't exist.

The names were updated as well. It is now

com.squareup.okhttp3:okhttp-urlconnection:3.0.0

NOte the okhttp3 instead of okhttp.

For more information on the reasoning behind this, see Jake Wharton (the author)'s blog post on Java Interoperability Policy for Major Version Updates here:

https://jakewharton.com/java-interoperability-policy-for-major-version-updates/

See jCenter.

like image 151
Tim Avatar answered Oct 08 '22 12:10

Tim