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?
Add this in build.gradle (Module:app)
android {
useLibrary 'org.apache.http.legacy'
}
its working
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With