Karlom
Karlom

Reputation: 14864

Cannot import AndroidHttpClient;

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?

Upvotes: 2

Views: 3403

Answers (2)

Shahzad Akhtar
Shahzad Akhtar

Reputation: 31

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'

Upvotes: 0

Veeresh Charantimath
Veeresh Charantimath

Reputation: 4719

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

Upvotes: 1

Related Questions