且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

org.apache.http.entity.FileEntity 在 Android 6 (Marshmallow) 中被弃用

更新时间:2021-10-24 05:50:05

如果您将 compileSdkVersion 更改为 21,您的应用程序将干净利落地编译.话虽如此,Google 退出内置 HttpClient 实现是有原因的,因此您可能应该寻求其他一些库.那其他图书馆"可能是:

If you change your compileSdkVersion to 21, your app will compile cleanly. That being said, there are reasons why Google is backing away from the built-in HttpClient implementation, so you probably should pursue some other library. That "some other library" could be:

  • the built-in classic Java HttpUrlConnection, though as you have found, its API leaves something to be desired
  • Apache's independent packaging of HttpClient for Android
  • OkHttp (my recommendation)
  • AndroidAsync

特别是 OkHttp 似乎有一个非常好的 API 用于发布文件发布多部分表单,这应该类似于您的 HttpClient 代码

In particular, OkHttp seems to have a pretty good API for posting a file and posting a multipart form, which should be similar to what your HttpClient code is doing.