Question Detail

Gradle help : Cannot resolve method HttpClient in Android Studio

6 years ago Views 2817 Visit Post Reply

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

these cannot resolve Method I have tried ?????????????

compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
Still Not Working How to resolve this issue?

Thread Reply

Bili Greed

- 6 years ago

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 and above, add this in your build.gradle:

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