无法在 Android Studio 中导入 org.apache.http.HttpResponse [英] Can't import org.apache.http.HttpResponse in Android Studio

查看:193
本文介绍了无法在 Android Studio 中导入 org.apache.http.HttpResponse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Android Studio 中使用这些库:

I want to use these libraries in Android Studio:

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

我正在关注一个视频教程,其中导师使用 Eclipse,所以我知道它有效.

I am following a video tutorial in which the tutor is using Eclipse so I know it works.

但是我必须向 Android Studio 添加哪些额外的东西/库才能使用它们?

But what additional things/libraries do I have to add to Android Studio in order to use them?

推荐答案

HttpClient 在 Android 5.1 中已弃用,并从 Android 6.0 中的 Android SDK 中删除.虽然有 一种在 Android 6.0 中继续使用 HttpClient 的解决方法使用 Android Studio,您确实需要转向其他方面.那个别的东西"可能是:

HttpClient was deprecated in Android 5.1 and is removed from the Android SDK in Android 6.0. While there is a workaround to continue using HttpClient in Android 6.0 with Android Studio, you really need to move to something else. That "something else" could be:

  • the built-in classic Java HttpUrlConnection
  • Apache's independent packaging of HttpClient for Android
  • OkHttp (my recommendation)
  • AndroidAsync

或者,根据 HTTP 工作的性质,您可以选择支持高阶操作的库(例如,Retrofit for Web 服务 API).

Or, depending upon the nature of your HTTP work, you might choose a library that supports higher-order operations (e.g., Retrofit for Web service APIs).

在紧要关头,您可以通过在模块的 android 闭包中包含 useLibrary 'org.apache.http.legacy' 来启用旧版 APIbuild.gradle 文件.但是,Google 多年来一直建议人们停止使用 Android 的内置 HttpClient,因此,这最多应该是一个权宜之计,而您正在努力更持久地转向另一个 API.

In a pinch, you could enable the legacy APIs, by having useLibrary 'org.apache.http.legacy' in your android closure in your module's build.gradle file. However, Google has been advising people for years to stop using Android's built-in HttpClient, and so at most, this should be a stop-gap move, while you work on a more permanent shift to another API.

这篇关于无法在 Android Studio 中导入 org.apache.http.HttpResponse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆