![](/img/trans.png)
[英]Get file name from headers with DownloadManager in Android
[英]Android DownloadManager: How can I get the response headers?
这是响应的标题:
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 37888
Content-Type: application/octet-stream; charset=utf-8
Server: Microsoft-IIS/7.5
Set-Cookie: ASP.NET_SessionId=g4tidw45yqwztc55nv0zdu55; path=/; HttpOnly
Content-Disposition: attachment;
**filename=%e5%85%a5%e5%ad%a6%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a1%b9.doc**
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Mon, 26 Nov 2012 06:24:36 GMT
我可以通过名为Wireshark的软件获得此标题。
这是Java代码中的DownloadManager:
lastDownloadId = manager.enqueue(new DownloadManager.Request(uri)
.setAllowedNetworkTypes(
DownloadManager.Request.NETWORK_MOBILE
| DownloadManager.Request.NETWORK_WIFI)
.setAllowedOverRoaming(false)
.setTitle("MyTest")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDescription("Something Useful")
.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS, "abc.doc"));
我想在Java代码中获取标题,因此我可以获得此响应的文件名。
我怎样才能做到这一点? 谢谢。
DownloadManager
不支持Content-Disposition
标头吗? 您可以检查本地文件名是否与标头匹配。 如果没有,您将不得不直接使用HttpClient
或HttpURLConnection
下载文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.