7

In my Android app it says: org.apache.http.client.httpclient is deprecated. After some research I found out that Android has deprecated it in API 22. I have searched in the forum and tried: "The application has stopped", Searched google: "The application has stopped". So I have no idea what to do. I hope you guys can help me out. Well here is my code:

        try {

        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://www.URL.com");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();

        Log.e("log_tag", "connection success");
        //   Toast.makeText(getApplicationContext(), "pass", Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        Log.e("log_tag", "Error in http connection" + e.toString());
        Toast.makeText(getApplicationContext(), "Connection fail", Toast.LENGTH_LONG).show();

EDIT:

I'm trying to get some data of my Mysql database. Do you know a good tutorial about how this is done? Please let me know.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Albert-Jan
  • 315
  • 1
  • 3
  • 11

1 Answers1

6

Stop using it and use URLConnection instead. It's been 4 years Google recommends this. http://android-developers.blogspot.be/2011/09/androids-http-clients.html

If you want an external library with a nicer API, you can try OkHttp: http://square.github.io/okhttp/

BladeCoder
  • 12,779
  • 3
  • 59
  • 51
  • It's been 5 years and it's still trash. Better to continue using Apache's libraries like this: http://stackoverflow.com/a/37623038/1727132 – Jehy Jun 03 '16 at 20:47
  • If you need to choose between including Apache HttpClient or OkHttp as an external library, I would recommend OkHttp over Apache HttpClient. It's 2016 and transparent GZip compression, support for HTTP2 and response caching are mandatory in the mobile world. – BladeCoder Jun 13 '16 at 10:00