Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpClient is deprecated (android studio, Target=api 22) [duplicate]

Tags:

java

android

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.

like image 761
Albert-Jan Avatar asked Jul 04 '15 12:07

Albert-Jan


1 Answers

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/

like image 196
BladeCoder Avatar answered Oct 10 '22 19:10

BladeCoder