2

I'm learning android restful web services using a 2014 tutorial by Lynda. The code uses this httpManager class :

   import android.net.http.AndroidHttpClient;

    public class HttpManager {

        public static String getData(String uri) {
            HttpClient client = AndroidHttpClient.AndroidHttpClient.netInstance("AndroidAgaent");
            HttpGet request = New HttpGet(uri);
            HttpResponse response;

            try {
                response = client.execute(request);
                return EntiyUtils.toString(response.getEntinity());
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            } finally {
                client.close();
            }
        }
    }

However, android studio says:

Cannot resolve symbol 'AndroidHttpClient'

I set minSdkVersion 8 but still could not solve the issue.

I'm wondering how to resolve this issue, or if the class has discarded, how to replace the code with a current class that is supported out of the box?

Karlom
  • 13,323
  • 27
  • 72
  • 116
  • 1
    https://stackoverflow.com/questions/32949626/org-apache-http-entity-fileentity-is-deprecated-in-android-6-marshmallow – CommonsWare May 29 '16 at 13:30
  • Thanks for the tip CommonsWare. So is okhttp still your personal recommendation? – Karlom May 29 '16 at 13:33
  • 2
    If you are limiting yourself to "a current class that is supported out of the box", your only choice is `HttpURLConnection`. If you are willing to use a library, I recommend the Square family of HTTP libraries: OkHttp3 (general HTTP), Retrofit (Web services), and Picasso (images). – CommonsWare May 29 '16 at 13:35
  • How does the square family compares against Volly? It sounds pretty awsome: http://code.tutsplus.com/tutorials/an-introduction-to-volley--cms-23800 – Karlom May 29 '16 at 15:29
  • 1
    Volley is fine. It has mixed support from Google and very little documentation, which is why I do not recommend it. – CommonsWare May 29 '16 at 15:36

2 Answers2

1

I think AndroidHttpClient is deprecated now, try out new HTTP which are available and very powerful than the former!

  1. http://square.github.io/retrofit/

  2. https://github.com/koush/ion

  3. https://developer.android.com/training/volley/index.html

Personally I would recommend Retrofit

Veeresh Charantimath
  • 4,641
  • 5
  • 27
  • 36
0

If you are using Android Studio, add these dependencies in your gradle build:

compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'

eli-k
  • 10,898
  • 11
  • 40
  • 44