在 Android 浏览器中 PDF 下载失败 [英] PDF download fails in Android Browser

查看:20
本文介绍了在 Android 浏览器中 PDF 下载失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态生成 pdf 的 ASP.Net WebForm.pdf 下载适用于所有桌面浏览器,以及 iPad、Chrome 移动版和 Firefox 移动版.但是,在 Android 浏览器中 pdf 下载失败,通知区域中显示消息下载失败".我正在使用此代码将 pdf 写入响应:

I have an ASP.Net WebForm that dynamically generates a pdf. The pdf download works in all the desktop browsers, as well as the IPad, Chrome mobile, and Firefox mobile. However, the pdf download fails in the Android browser with the message "Download Unsuccessful" in the notification area. I am writing the pdf to the response with this code:

using (PdfDocument pdf = this.RenderPDF())
using (MemoryStream stream = new MemoryStream())
{
    pdf.Save(stream, false);
    response.Clear();
    response.AddHeader("content-disposition", "inline;filename=myPdf.pdf");
    response.AddHeader("content-length", stream.Length.ToString());
    response.ContentType = "application/pdf";
    response.BinaryWrite(stream.ToArray());
    response.Flush();
    stream.Close();
    response.End();
}

我应该怎么做才能让 pdf 下载在 Android 浏览器中工作?

What should I do differently to get the pdf download working in the Android browser?

推荐答案

既然你说 PDF 是由表单生成的,我假设它是对 POST 的响应.我遇到了同样的问题,发现 此评论 关于类似的 S/O 问题:

Since you said the PDF is generated by a form, I'm assuming that's in response to a POST. I'm having the same problem, and found this comment on a similar S/O question:

问题是由 Android 浏览器和 Dolphin 中的错误引起的,该错误会导致 POST 操作下载失败.作为解决方法,我将操作更改为 GET.

issue is due to a bug in the Android browser and Dolphin, which causes downloads to fail on POST actions. I changed my actions to GET as a workaround.

引用的问题是支持下载 POST 响应- 自 2009 年开始营业!

The issue referenced is Support download of POST responses - open since 2009!

(这个问题在 S/O 上有几个尚未解决的迭代;关闭和回答它们似乎都不合理,那么一些链接怎么样:

(This question has several yet-unresolved iterations on S/O; neither closing nor answering them all seems reasonable, so how about some links:

这篇关于在 Android 浏览器中 PDF 下载失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆