Gradle 同步成功后,无法在 Android Studio 中使用 HttpPost

Cas*_*ins 1 android http-post gradle

我正在尝试像以前在 Android 中那样使用 HttpPost 。我意识到它已从最近的 Android 版本中删除。按照类似 StackOverflow 问题的解决方案,我将其添加到我的 Gradle 依赖项中:

compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
Run Code Online (Sandbox Code Playgroud)

在 Gradle 同步没有错误后,我仍然无法导入 HttpPost 程序。事实上,org.apache.http.client.methods 包根本无法解析。

我还尝试了 Apache HttpClient 网站的建议,即在我的 Gradle 依赖项中使用它:

compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
Run Code Online (Sandbox Code Playgroud)

同步再次顺利进行,这次包已解析,但 HttpPost 程序未解析。

在此输入图像描述

如果有任何建议,我将不胜感激。

Yur*_*sap 5

build.gradle只需在你的Android 插件中添加这一行:

useLibrary 'org.apache.http.legacy'
Run Code Online (Sandbox Code Playgroud)