Android 6.0 SDK无法使用HttpClient的解决办法

1,027 阅读1分钟

前言

转自Google官博 *Android 6.0 release removes support for the Apache HTTP client. If your app is using this client and targets Android 2.3 (API level 9) or higher, use the HttpURLConnection class instead. *

Google为了强推HttpURLConnection,直接在Android 6.0 SDK中移除了Apache HttpClient库支持,不过并没有把这条路堵死,并给出了解决办法,看来Google也不敢乱来啊^_^

解决办法

eclipse ADT

libs中加入.\sdk\platforms\android-23\optional\org.apache.http.legacy.jar

Android Studio

在对应的Module下的build.gradle中加入:

android {
    useLibrary 'org.apache.http.legacy'
}

虽然Google给出了解决办法,但还是推荐大家使用轻量级的HttpURLConnection,毕竟官方支持。

迁移自我的简书 2016.01.25