java - 导入 Apache HTTP 组件 Android Studio 1.3.2

标签 java android

我正在尝试使用 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/

相关文章:

java - 找到两个链表的合并节点?

java - Android从网站下载txt而不去除包装

android - 迁移到 Androidx 后,在模块 guava 错误中发现重复的类 com.google.common

android - Android 上的 NV21 转位图,图像非常暗、灰度还是黄色?

android - 带 BiChannelGoogleApi : [FirebaseAuth: ] getGoogleApiForMethod() returned Gms

java - 终止 Swing Worker

java - Spring Boot 安全表单登录和 Oauth2 资源服务器

java - 数据库中的随机值

java - Swing:无法让 JButton 更新 - repaint() 不工作

android - 日历和 PagerAdapter - 无限制的 View