我正在尝试使用 Apache HTTP 组件为我的 Android 应用程序提供实时货币汇率。我有以下代码来导入它们,但有错误
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;
我尝试过以下 JAR http://www.java2s.com/Code/Jar/h/Downloadhttpclient403jar.htm没有运气。还有其他方法可以实现吗?
最佳答案
Apache HTTP 客户端现已弃用。您需要使用 HttpURLConnection
而是调用网络电话。
请参阅此处的发行说明以获取更多信息: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'
}
关于java - 导入 Apache HTTP 组件 Android Studio 1.3.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35780729/