【发布时间】:2011-04-28 22:10:11
【问题描述】:
因此,Android 浏览器或 webview 可以很好地处理这样的网址 - abc.com/xyz.txt
但是,如果您的 URL 看起来像这样 - abc.com/xyz.php 并且在标头中发送到浏览器的是 - Content-Disposition: attachment; filename="xyz.txt",那么 Android 浏览器和 web 视图似乎变得非常混乱。
看起来它在手机上保存了正确的文件名,但内容是之前正在查看的网页。这在基于 PC 的浏览器以及 iPhone 和 Blackberry 上运行良好,这只是 Android 2.1 和 2.2 上的问题(尚未测试其他版本)。
有人有解决办法吗?将不胜感激。我真的不想开始存储静态文件,而是想即时生成我的下载内容。手机上的日志没有发现任何线索。
这是服务器向浏览器发送的内容
===================== start content ====================================
HTTP/1.1 200 OK
Date: Thu, 21 Oct 2010 21:22:11 GMT
Server: Apache
Content-Disposition: attachment; filename="Wafty.txt"
Content-length: 30
Content-Type: text/plain; charset=ISO-8859-1
Hello this is a test of a file
========= There was no carriage return at the end of the above line ====
【问题讨论】:
-
即时生成下载内容,存储到临时文件中,然后发出 301 重定向。通过 cron 作业/计划任务清理生成的内容。这可能很尴尬——这只是一个想法。
-
@CommonsWare:这冒犯了我的感情! :-)
-
尝试将 Content-Type 更改为
application/octet-stream。
标签: android webview download content-disposition