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

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

问题描述

我想在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的视频教程,所以我知道它是有效的。 p>

但是,为了使用它们,我必须添加什么额外的东西/图库?

解决方案

HttpClient在Android 5.1中已弃用,并已从Android 6.0中的Android SDK中删除。虽然在Android 6.0中继续使用HttpClient的解决方法使用Android Studio ,您真的需要转到别的地方。 其他可能是:





或者,根据您的HTTP工作的性质,您可以选择一个支持高阶操作的库(例如,Web服务API的改造)。



可以通过在您的 android 闭包中使用 useLibrary'org.apache.http.legacy'来启用传统API模块的 build.gradle 文件。不过,Google多年来一直在为人们建议停止使用Android的内置HttpClient,因此,最重要的是,这应该是一个暂停的举措,而您正在更加永久地转移到另一个API。


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;

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

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

解决方案

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:

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).

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天全站免登陆