SANTOSH VERMA SANTOSH VERMA - 4 months ago 32
Java Question

Error while importing http packages in android studio 2.1

Hey there I am importing few http packages for communication but I am getting error in these lines:

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;


I am using latest android studio. Any help regarding importing these packages?
I came to know that http packages are deprecated for android. To use above mentioned packages which package should I import ?
Thank you.

Answer

@Santosh Yes httpclient has been deprecated in Android 5.1 and has been removed from the Android SDK in Android 6.0. You can read about this in more detail on this link

https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client

To fix your problem you just need to add this line in android tag in build.gradle file useLibrary 'org.apache.http.legacy' Hope this helps.

Comments