I have a simple class written in Android Studio:
package com.mysite.myapp;
import org.apache.http.client.HttpClient;
public class Whatever {
public voi
HttpClient was deprecated in API Level 22 and removed in API Level 23. You can still use it in API Level 23 and onwards if you must, however it is best to move to supported methods to handle HTTP. So, if you're compiling with 23, add this in your build.gradle:
android {
useLibrary 'org.apache.http.legacy'
}
Which API target do you have within your project?AndroidHttpClient
is only for API Level 8 <.
and please have a look on here
enjoy your code:)
You can simply add this to Gradle dependencies:
compile "org.apache.httpcomponents:httpcore:4.3.2"
HttpClient is not supported any more in sdk 23. Android 6.0 (API Level 23) release removes support for the Apache HTTP client. You have to use
android {
useLibrary 'org.apache.http.legacy'
.
.
.
and also add below code snippet in your dependency :
//http final solution for web-service (including file uploading)
compile('org.apache.httpcomponents:httpmime:4.3.6') {
exclude module: 'httpclient'
}
compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
It will also help you while you use Use MultipartEntity for File upload.
1- download Apache jar files (as of this answer) 4.5.zip file from:
https://hc.apache.org/downloads.cgi?Preferred=http%3A%2F%2Fapache.arvixe.com%2F
2- open the zip copy the jar files into your libs folder. You can find it if you go to the top of your project where it says "Android" you'll find a list when u click it. So,
Android -> Project -> app -> libs
,Then put jars there.
3- In build.gradle (Module: app) add
compile fileTree(dir: 'libs', include: ['*.jar'])
in
dependency {
}
4- In the java class add these imports:
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
If you need sdk 23, add this to your gradle:
android {
useLibrary 'org.apache.http.legacy'
}