2

I need to send HTTP POST message in Android. I have seen many way to do it. But the accepted answers are using deprecated classes, or approachas are far from the most efficient solutions. Apple moved from NSURLConnection to NSURLSession. Is it any similar framework in Android too?

I read here that i.e. HttpUrlConnection and HttpClient are not recommended to use, but I do not want to use 3rd party library.

Community
  • 1
  • 1
János
  • 32,867
  • 38
  • 193
  • 353
  • 1
    Please consider using a plug-in such as Retrofit, Volley or such. No need to reinvent the wheel. all of those plug-ins will do any requests (GET, POST, etc) asynchronously and provide JSON mapping, and will save you a ton of boilerplate code. Welcome to Android development! – C0D3LIC1OU5 Sep 08 '16 at 14:26
  • What you mean plug-in? I am looking for **standard** class / framework. No 3rd party solution. It is written in the question. – János Sep 08 '16 at 14:27
  • Hence I went with "please consider" and a comment, not an answer. If you cant' or don't want to use a 3rd party solution, just wait for actual answers. – C0D3LIC1OU5 Sep 08 '16 at 14:34
  • Just for the record, would you consider Google a 3rd party? Because they are the ones maintaining Volley (https://developer.android.com/training/volley/index.html) – C0D3LIC1OU5 Sep 08 '16 at 15:04
  • 1
    If you change your mind, then you could perhaps take a look at http://square.github.io/okhttp/ or one of the other 3rd party suggestions that has already been mentioned like Volley – Caleb Sep 08 '16 at 19:14

1 Answers1

1

You dont have much choice.

HttpClient is deprecated, but still works.

HttpUrlConnection is ok, if you dont have plan to write app for dinosaurs. I use it anyway in corporate app android 2.3+ and dont have problems with it.

Or 3rd party libraries like Retrofit or Volley.

There are other ways but they are even worse than just 3rd party library, like using Android NDK.

Andrey Danilov
  • 6,194
  • 5
  • 32
  • 56
  • There's a way to import a more current version of `HttpClient`, but it was made by Apache, so a 3rd party. http://stackoverflow.com/questions/29150184/httpentity-is-deprecated-on-android-now-whats-the-alternative/29150361#29150361 – C0D3LIC1OU5 Sep 08 '16 at 15:02
  • well if you are ready to import something, Retrofit is better, if not just use HttpUrlConnection, srsly I dont think you use something that hard for it. – Andrey Danilov Sep 08 '16 at 15:04
  • if we are talking about ways, you can import cURL to android NDK for example, but its not best decision still. – Andrey Danilov Sep 08 '16 at 15:06
  • That's not the same because the default `HttpClient` client that was bundled with Android was actually a forked Apache `HttpClient` that wasn't really maintained. So importing a new version is seems closer to the original client. – C0D3LIC1OU5 Sep 08 '16 at 15:11