已弃用的DefaultHttpClient的替换 [英] Replacement for deprecated DefaultHttpClient
问题描述
我在我当前的应用中使用 DefaultHttpClient
。
I am using DefaultHttpClient
in my current app.
我读过这篇文章,声明 DefaultHttpClient
已被弃用: http://developer.android.com/reference/org/apache/http/impl/client/DefaultHttpClient .html
I read this article which states that the DefaultHttpClient
is deprecated: http://developer.android.com/reference/org/apache/http/impl/client/DefaultHttpClient.html
它指向这个网站: http://android-developers.blogspot.com/2011/09/androids-http-clients.html?m=1 这也是旧的和写在2011年。
It points to this website: http://android-developers.blogspot.com/2011/09/androids-http-clients.html?m=1 which is too old and written in 2011.
我将使用 DefaultHttpClient
删除并按照本文使用Apache的 HttpClient
: http://loopj.com/android-async -http /
I am going to drop using DefaultHttpClient
and follow this article which uses Apache’s HttpClient
: http://loopj.com/android-async-http/
我想知道这是2015年编程时针对Android API 19及以上版本的正确路径。
I wonder if this is the right path to take when programming in 2015 targeting android API 19 and above.
推荐答案
好的,我等了一个星期,所以做了很多研究。我想我找到了答案。
Ok I waited for a week and so and did all lots of researches. I think I have found the answer.
我强烈建议初学者甚至专业的Android程序员知道存在非常有用的库名为Retrofit:
I strongly advise for beginners and even professional Android programmers to know the existence of very helpful library called Retrofit:
http://square.github.io/retrofit/ 提供了大量文件
堆栈溢出还提供了几乎所有需要通过网络联系远程REST服务的示例。
The Stack overflow also has samples for almost everything one need to do over a network to contact a remote REST service.
最好停止使用HttpURLConnection和AsyncTask。改造速度更快,并支持开箱即用的所有故障情况。
It is better to stop using HttpURLConnection and AsyncTask. Retrofit is way faster and supports all failure situations out of the box.
这篇关于已弃用的DefaultHttpClient的替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!