Amb*_*ran 9 java android httpurlconnection apache-commons-httpclient android-6.0-marshmallow
我正在将应用升级到org.apache.http不推荐使用的API 23 .
我当前(已弃用)的代码如下所示:
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());
Run Code Online (Sandbox Code Playgroud)
我已经找到了一些关于如何使用它的建议HttpURLConnection,但它们比当前的解决方案(不能再使用)复杂得多.我正在谈论用于执行与上述相同功能的许多代码行.
有没有人有一个很好的固定更短的解决方案呢?
如果将您更改compileSdkVersion为21,您的应用程序将完全编译.话虽如此,谷歌有理由退出内置的HttpClient实现,所以你可能应该追求其他一些库.那个"其他一些图书馆"可能是:
HttpUrlConnection,虽然你已经发现,它的API仍然有待改进特别是,OkHttp似乎有一个非常好的API用于发布文件和发布多部分表单,这应该与您的HttpClient代码正在做的类似.
| 归档时间: |
|
| 查看次数: |
4053 次 |
| 最近记录: |