Android DownloadManager: how can I get response headers?

Here is the response header:

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 

I can get this header using Wireshark software.

Here is the DownloadManager in Java code:

 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")); 

and I want to get the header in Java code, so I can get the name of this answer.

How can i do this? Thanks.

+4
source share
1 answer

Does the DownloadManager match the Content-Disposition header? You can check if the name of the local file matches the header. If not, you will have to download the file directly using HttpClient or HttpURLConnection .

+1
source

All Articles