【问题标题】:How can i find which Android API versions does OkHttp 3.14 supports?如何找到 OkHttp 3.14 支持的 Android API 版本?
【发布时间】:2020-10-13 11:45:06
【问题描述】:

我正在使用 OKHTTP 3.14 并且我的设备有 API 24 (android 7.0),它支持吗? 因为在更高级别的设备中发出 http 请求时,它工作得非常好,但在 API 级别 24 的设备中却不行。

编辑: 当我在下面运行这个函数时,它可以在比 24 更新的 API 中运行,但是当我在 API 级别 24 的旧设备上运行它时,它会引发异常:

private String get_OKHttp3Response(String _uri) {
OkHttpClient httpClient = new OkHttpClient();
String strResp = "";
try {
    Request request = new Request.Builder().url(_uri).build();
    Response response = httpClient.newCall(request).execute();
    if (!response.isSuccessful()) {
        throw new IOException("Unexpected code " + response);
    }
    strResp = response.body().string();
    if (!strResp.equalsIgnoreCase("")) {
        return strResp;
    } else {
        return "";
    }
} catch (Exception e) {
    System.out.println( "get_OKHttp3Response Exception: " + e.getMessage() );
    return "";
}

};

我在抛出异常时收到此消息:

Exception: null

【问题讨论】:

  • OkHttp 适用于 Android 5.0+(API 级别 21+)和 Java 8+。 (来自 github 自述文件)github.com/square/okhttp。最新版本是4.7.2,或许你可以尝试更新一下
  • 您尚未指定遇到的错误,也未向我们展示相关代码。我已经在 Android 5 到 Android 11 上成功使用了 OkHttp 3.14。
  • @Michael 看到编辑后的问题,我在那里发布了代码。
  • 请包含异常的堆栈跟踪。

标签: java android okhttp


【解决方案1】:

https://square.github.io/okhttp/security/

2020 年 6 月 25 日

╔═════════╦══════════════════╦════════════════════════════════════════════════════════════════════════════╗
║ Version ║    Supported     ║                                   Notes                                    ║
╠═════════╬══════════════════╬════════════════════════════════════════════════════════════════════════════╣
║ 4.x     ║ ✅                ║ Android 5.0+ (API level 21+) and on Java 8+.                               ║
║ 3.14.x  ║ Until 2020-06-30 ║                                                                            ║
║ 3.12.x  ║ Until 2021-12-31 ║ Android 2.3+ (API level 9+) and Java 7+. Platforms may not support TLSv1.2 ║
╚═════════╩══════════════════╩════════════════════════════════════════════════════════════════════════════╝

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    • 2021-02-09
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    相关资源
    最近更新 更多