Android HTTP POST下载管理器
问题描述:
在android中,我有这个URL,我必须做POST请求 返回的输入流的所述请求返回一个可下载的对象... 我该如何使用Android Downloadmanager本身或自定义创建一个,为我处理下载过程?Android HTTP POST下载管理器
答
的Android的下载管理器是相当简单:
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Request request = new Request(Uri.parse("http://www.theeUrl.fake/image.png"));
enqueue = dm.enqueue(request);
,你可以轻松地添加参数为GET请求。我不知道你是否可以从它发出POST请求。
编辑:做一个POST请求您可以使用HttpClient的是这样的:
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
HttpResponse response = null;
Dictionary<String, String> postFields = new Dictionary<String, String>();
// Set the post fields
postFields.add("username","toto")));
postFields.add("password", "thePassword45155")));
post.setEntity(new UrlEncodedFormEntity(postFields, HTTP.UTF_8));
// Execute the POST request
response = client.execute(post);
,你应该能够从获得的HttpResponse的InputStream要下载的文件。 但您必须自己管理显示/通知/取消...。
答
http://ootooban.com/en/2012/custom-download-manager-for-android-2-1-part2-resumable-downloads/
创建您自己的通知ontop的POST请求的,具有setProgress组合()&进度的伎俩,所以使用下载管理可悲的是没有确凿的方式
+0
链接不工作。 – 2017-08-23 06:30:27
什么是你的目标API? – 2013-03-03 14:10:47
最低支持2.3.6 在4.1平板电脑上开发,但它主要用于2.3.6 – jaggy 2013-03-03 14:14:06
看看这个http://stackoverflow.com/questions/2323617/android-httppost-how-to-get-the-result帮助。 – 2013-03-03 14:20:24