我有一个Web应用程序,允许用户下载PDF文件.它是ASP.NET MVC,它在桌面浏览器,iPhone,Android Chrome以及覆盖Web View setDownloadListener()的原生Android应用程序中都能正常运行.
但是,使用默认Android浏览器时,下载似乎不起作用.我正在测试运行4.2.2的Galaxy Nexus和运行2.3.7的Nexus S 4g.我在两台设备上都安装了PDF查看器应用程序.
当我在Android Chrome中测试时,用户会看到"正在开始下载..."吐司,然后状态栏中会显示下载完成通知.用户可以触摸此通知以在pdf查看器中打开文件.在Android的默认浏览器中,没有toast,也没有保存下载文件.
我把wireshark放在网络上,我看到以下请求:
GET /appapth/ViewPDF/8383600280757433_11_05_2012 HTTP/1.1
Host: 192.168.1.117
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
X-Requested-With: com.google.android.browser
User-Agent: Mozilla/5.0 (Linux; U; Android 4.2.2; en-us; Galaxy Nexus Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
Accept-Encoding: gzip,deflate
Accept-Language: en-US
Accept-Charset: utf-8, iso-8859-1, utf-16, *;q=0.7
Cookie: (lots o'cookie data)
Run Code Online (Sandbox Code Playgroud)
并且响应是:
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Content-Type: application/pdf
Content-Encoding: gzip
Expires: -1
Server: Microsoft-IIS/7.5
Set-Cookie: ___TempData=; path=/
Set-Cookie: ___TempData=(lot's o'cookie data); path=/; HttpOnly …Run Code Online (Sandbox Code Playgroud) 我在使用rails的服务器上提供APK时遇到问题.如果下载链接放入/公开,我可以提供APK.但是,我想用密码保护它.如果我将文件移到需要HTTP身份验证的URL后面,那么它会Download Unsuccessful立即在股票浏览器上失败.
如果我安装并运行firefox,firefox可以下载APK并正确安装.
有人知道如何使用Android的股票浏览器吗?
我已经添加MIME Type到服务器:
Mime::Type.register "application/vnd.android.package-archive", :apk
Run Code Online (Sandbox Code Playgroud)
而我正在尝试在HTTP身份验证后面发送send_file:
send_file "android.apk", :type => 'application/vnd.android.package-archive'
Run Code Online (Sandbox Code Playgroud)
来自/ public的成功HTTP标头:
~ curl -s -D- android.apk -o/dev/null
HTTP/1.1 200 OK
Server: nginx/1.4.1
Date: Thu, 11 Jul 2013 20:06:43 GMT
Content-Type: application/octet-stream
Content-Length: 38673086
Last-Modified: Thu, 11 Jul 2013 20:05:12 GMT
Connection: keep-alive
ETag: "51df0ff8-24e1abe"
Accept-Ranges: bytes
Run Code Online (Sandbox Code Playgroud)
HTTP身份验证后面的HTTP头不成功:
~ curl -s -D- private/android.apk -o/dev/null
HTTP/1.1 200 OK
Server: nginx/1.4.1
Date: Thu, 11 Jul 2013 20:11:53 GMT
Content-Type: application/octet-stream
Transfer-Encoding: chunked
Connection: …Run Code Online (Sandbox Code Playgroud) 我有一个Web应用程序,可以在点击事件中流式传输PDF文件,它可以在IE,Firefox和Safari中正常工作,但在Chrome中它永远不会下载.下载只是读取"中断".Chrome处理流媒体有何不同?我的代码看起来像:
this.Page.Response.Buffer = true;
this.Page.Response.ClearHeaders();
this.Page.Response.ClearContent();
this.Page.Response.ContentType = "application/pdf";
this.Page.Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
Stream input = reportStream;
Stream output = this.Page.Response.OutputStream;
const int Size = 4096;
byte[] bytes = new byte[4096];
int numBytes = input.Read(bytes, 0, Size);
while (numBytes > 0)
{
output.Write(bytes, 0, numBytes);
numBytes = input.Read(bytes, 0, Size);
}
reportStream.Close();
reportStream.Dispose();
this.Page.Response.Flush();
this.Page.Response.Close();
Run Code Online (Sandbox Code Playgroud)
关于我可能缺少什么的任何建议?