【问题标题】:Using Retrofit API With Android 2.2在 Android 2.2 中使用 Retrofit API
【发布时间】:2015-06-10 06:45:11
【问题描述】:

我必须构建一个访问响应 json 的 php 脚本的 android 应用程序。 我迁移到 android studio,目标为 android sdk 22 (5.0),有最低 8(Froyo)的sdk并构建了项目。

问题发生在我过去在 Eclipse 上使用的代码处 在不工作的地方启动“httppost”请求。

logcat 显示“未知主机异常”的 url 作为字符串传递。

当我从“defaulthttpclient”更改为“httpurlconnection”时 它工作,但连接太慢。 (在安卓 2.2 上)

我了解到“Retrofit”api 是一个很好的快速 http 请求库, 但我阅读了两份相互矛盾的报告:

     The minimum sdk for retrofit is android 2.3

然后

  Retrofit uses httpurlconnection on android 2.3+ and httpclient on androd 2.2

这让我有点困惑。所以真正的问题是

  Can retrofit handle my http requests on an android 2.2 phone?

【问题讨论】:

    标签: retrofit androidhttpclient


    【解决方案1】:

    是的,但您必须使用 pre2.0 okhttp、urlconnection 或 apache 客户端运行改造。

    最新版本的 okhttp 需要 Java7 或 android 2.3+

    https://square.github.io/retrofit/#download

    https://github.com/square/retrofit/issues/826

    https://github.com/square/okhttp/issues/528#issuecomment-96622594

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-18
      • 1970-01-01
      • 2017-09-22
      • 2018-02-01
      • 2022-01-23
      • 2016-03-01
      • 1970-01-01
      • 2020-06-25
      相关资源
      最近更新 更多