Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android studio Cannot resolve symbol 'HttpClient' [duplicate]

I have an Android Project and I need to use an http call.

I use this simply code:

public void onGetClick(View v) {
    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet("http://www.google.com");
    HttpResponse response = client.execute(request);

    BufferedReader rd = new BufferedReader(new InputStreamReader
(response.getEntity().getContent()));

    String line = "";
    while ((line = rd.readLine()) != null) {
        Log.d("WM.ALS", line);
    }

}

but I cannot find the HttpClient library.

I added into dir /lib the .jar file downloaded from Apache (http://hc.apache.org/downloads.cgi) and into the "build.gradle(Module: app)" file, i added:

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:appcompat-v7:23.1.1'

  compile 'com.android.support:design:23.0.1'
  compile 'org.apache.httpcomponents:httpcore-4.4.3'
  compile 'org.apache.httpcomponents:httpclient-4.5.1'

}

But still don't work..

How do I do?

like image 426
img.simone Avatar asked Dec 05 '22 18:12

img.simone


1 Answers

Add this in build.gradle (Module:app)

android {
    useLibrary 'org.apache.http.legacy'
}

its working

like image 148
RushDroid Avatar answered Dec 09 '22 13:12

RushDroid