OkHttp(s)URLConnection class 在 4.9.0 版本中不可用
OkHttp(s)URLConnection class is not available in 4.9.0 version
我在 Android 的 gradle 文件中有 com.squareup.okhttp3:okhttp-urlconnection:3.13.1 jar 作为依赖项项目并按如下方式使用以获取 URLConnection。
protected URLConnection getStandardHTTPURLConnection(URL url) throws IOException {
return new OkHttpURLConnection(url, builder.cookieJar(new JavaNetCookieJar(CookieHandler.getDefault())).build());
}
所以我将 jar 更新到 4.9.0 并意识到 OkHttpURLConnection 不可用。它在 运行 时间导致 noClassDefinition 异常。那么有哪些选择呢?它是否已弃用或移到另一个引擎盖下?
以下是我的导入。
import okhttp3.internal.huc.OkHttpURLConnection;
import okhttp3.internal.huc.OkHttpsURLConnection;
多多指教。
来自 https://square.github.io/okhttp/changelog_3x/ 所以我猜他们在 4.x
上被删除了
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.
您可以粘贴 OkHttp 3.14.0 发行说明中提到的兼容性实现。
我在 Android 的 gradle 文件中有 com.squareup.okhttp3:okhttp-urlconnection:3.13.1 jar 作为依赖项项目并按如下方式使用以获取 URLConnection。
protected URLConnection getStandardHTTPURLConnection(URL url) throws IOException {
return new OkHttpURLConnection(url, builder.cookieJar(new JavaNetCookieJar(CookieHandler.getDefault())).build());
}
所以我将 jar 更新到 4.9.0 并意识到 OkHttpURLConnection 不可用。它在 运行 时间导致 noClassDefinition 异常。那么有哪些选择呢?它是否已弃用或移到另一个引擎盖下?
以下是我的导入。
import okhttp3.internal.huc.OkHttpURLConnection;
import okhttp3.internal.huc.OkHttpsURLConnection;
多多指教。
来自 https://square.github.io/okhttp/changelog_3x/ 所以我猜他们在 4.x
上被删除了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.
您可以粘贴 OkHttp 3.14.0 发行说明中提到的兼容性实现。