org.apache.http.entity.FileEntity is deprecated in Android 6 (Marshmallow)

后端 未结 3 2192
粉色の甜心
粉色の甜心 2020-11-22 13:46

I\'m upgrading an app to API 23 where org.apache.http is deprecated.

My current (deprecated) code looks like this:

HttpClient httpClient         


        
3条回答
  •  自闭症患者
    2020-11-22 13:53

    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

    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.

提交回复
热议问题