在Android 6(Marshmlow)中不推荐使用org.apache.http.entity

在Android 6(Marshmlow)中不推荐使用org.apache.http.entity.FileEntity

我正在升级一个应用程序到API 23org.apache.http不受欢迎。

我当前(不推荐的)代码如下所示:

HttpClient httpClient = new DefaultHttpClient();File file = new File(attr.Value);String url = server_url;
HttpPost request = new HttpPost(url);FileEntity fileEntity = new FileEntity(file, "image/png");
request.setEntity(fileEntity);HttpResponse response = httpClient.execute(request);String output = getContent(response.getEntity().getContent());

我发现了一些关于如何使用HttpURLConnection,但是它们都比当前的解决方案复杂得多(不能再使用了)。我正在讨论许多代码行,用于执行与上面相同的功能。

例如:本页本页

有人有一个好的固体物较短的解决方案吗?


慕村9548890
浏览 932回答 3
3回答

一只萌萌小番薯

HTTPClient最好的替代方法是使用volley。它更容易使用,处理请求队列和缓存您的请求。它完全兼容几乎所有的API级别,直到API 4。见Android文档怎么做。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android
Java