0

What android API's work with the HttpPost function and what android API's work with the HttpURLConnection function? I'm trying to create Java code for an android app that calls a PHP file to connect with a database, and I want to make sure that my code is compatible with whatever Android API the mobile phone is running on.

jerbear
  • 41
  • 1
  • 10

2 Answers2

2

Apache HTTP, and therefore HttpPost, is deprecated, HTTPURLConnection is encouraged, but it really doesn't matter.

You could even use Retrofit, Ion, AsyncHttpClient, Volley, OkHttp ... And the Android HTTP library list goes on.

If you are truly concerned about API version, use HttpURLConnection

If you want to use legacy Apache HTTP, then compile it

android {
    compileSdkVersion ...
    buildToolsVersion "..."
    useLibrary 'org.apache.http.legacy' // Add this line
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
1

From Android Developers Blog:

Which client is best?

Apache HTTP client has fewer bugs on Eclair and Froyo. It is the best choice for these releases.

For Gingerbread and better, HttpURLConnection is the best choice. Its simple API and small size makes it great fit for Android. Transparent compression and response caching reduce network use, improve speed and save battery. New applications should use HttpURLConnection; it is where we will be spending our energy going forward.

nandsito
  • 3,782
  • 2
  • 19
  • 26