在Android 2.2中使用Retrofit API

时间:2015-06-10 06:45:12

标签: retrofit androidhttpclient

我必须构建一个访问一个回应json的php脚本的android应用程序。 我迁移到android工作室,目标是andoid sdk 22(5.0),最低限度 sdk of 8(Froyo)并建立了这个项目。

障碍发生在我过去在eclipse上使用的代码的地方 推出" httppost"请求不工作的地方。

logcat显示了一个未知的主机异常"对于那里的网址 作为字符串传递。

当我改变" defaulthttpclient"到" httpurlconnection" 它工作,但连接太慢。 (在Android 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?

1 个答案:

答案 0 :(得分:0)

是的,但您必须使用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