0

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?

1

2 Answers 2

1

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'
}
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.