android {
compileSdkVersion 28
buildToolsVersion "28.0.1"
useLibrary 'org.apache.http.legacy' //添加这一句可解决问题,本人亲测有效
defaultConfig {
applicationId "com.example.administrator.testz"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
原因竟是因为:
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. This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption. To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your build.gradle file:
因为大家的studio版本过高,谷歌在android6.0以后删除了这些网络请求的库,解决方法是添加下面这一句

本文介绍了Android 6.0以上版本移除Apache HttpClient支持的问题,建议使用HttpURLConnection替代,并提供了在build.gradle文件中添加依赖的解决方法。
最低0.47元/天 解锁文章
3058

被折叠的 条评论
为什么被折叠?



