OkHttp 3 和 HttpURLConnection

OkHttp 3 and HttpURLConnection

我有点困惑如何将 OkHttp 升级到 v3.0.0,同时保留我们使用 HttpURLConnection 的代码。 我们当前的依赖项是:

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

变更日志指出:

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.

很遗憾,我不清楚 "we're moving everything to the new OkHttp 3 API" 是什么意思。

我试图依赖 com.squareup.okhttp:okhttp-urlconnection:3.0.0 但那不存在。

我应该保留 com.squareup.okhttp:okhttp-urlconnection:2.7.0 并仅将 com.squareup.okhttp:okhttp 升级到 3.0.0 吗? 还是这句话的意思是只依赖com.squareup.okhttp:okhttp就可以了?

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

名称也已更新。现在是

com.squareup.okhttp3:okhttp-urlconnection:3.0.0

注意 okhttp3 而不是 okhttp

有关此背后原因的更多信息,请参阅 Jake Wharton(作者)的博客 post Java 主要版本更新的互操作性策略 这里:

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

参见jCenter