Android Cannot access org.apache.http.client.HttpClient

≯℡__Kan透↙ 提交于 2019-12-01 16:49:06

In Android SDK 23

HttpClient is deprecated because it inference, you can migrate your code in HttpURLConnection

https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client

You can use this, but it's not recommended anymore

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

For the HttpURLConnection

URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.setDoInput(true);
connection.connect();

This is because HttpClient is not supported in sdk 23 onwards now. Try adding this in your gradle.

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

if that doesn't works, just download HttpClient jar file and add to your library.

If still it is not working, you have to downgrade your compileSdkVersion to 22 or lower.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!