org.apache.http packages removed in API level 23. What is the alternative? org.apache.http packages removed in API level 23. What is the alternative? apache apache

org.apache.http packages removed in API level 23. What is the alternative?


See the Behavior Changes at Android Developers where it says that:

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:

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


Please refer this. Alternative class is mentioned in Android Developer site.

The org.apache.http classes and the android.net.http.AndroidHttpClient class have been deprecated in Android 5.1. These classes are no longer being maintained and you should migrate any app code using these APIs to the URLConnection classes as soon as possible.


You can manually add an up-to-date version of the Apache HttpClient:

implementation 'org.apache.httpcomponents:httpclient:4.5.5'

Likewise, you can use another HTTP library altogether like OkHttp. You can also use a library which is more higher level, like Retrofit.