Reputation: 31
I am trying to use Apache HTTP components to provide my android application with live currency rates. I have the following code to import these but have errors
import org.apache.http.HttpEntity;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;
I have tried the following JAR http://www.java2s.com/Code/Jar/h/Downloadhttpclient403jar.htm with no luck. Is there any other way of implementing this?
Upvotes: 0
Views: 116
Reputation: 1006554
You can use a fairly up-to-date independent packaging of Apache HttpClient via the cz.msebera.android:httpclient:4.4.1.1
artifact. So, in Android Studio, for the module where you want to use HttpClient, you would have:
dependencies {
compile 'cz.msebera.android:httpclient:4.4.1.1'
}
Note that the API for current editions of HttpClient, such as what you get from the above library, is different than the API for the deprecated-and-gone edition of HttpClient that was baked into Android and used to be part of the Android SDK.
Personally, I would recommend that you use OkHttp instead.
Upvotes: 0
Reputation: 3444
The Apache HTTP client is now deprecated. You'll want to use HttpURLConnection
instead to make web calls.
See the release notes for more info here: http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client
To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your build.gradle file:
android {
useLibrary 'org.apache.http.legacy'
}
Upvotes: 1