PDF下载失败的Andr​​oid浏览器 [英] PDF download fails in Android Browser

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

问题描述

我有一个ASP.Net Web窗体动态生成的PDF文件。 PDF格式下载适用于所有的桌面浏览器,以及在iPad,手机浏览器和Firefox移动。但是,PDF格式下载失败的Andr​​oid浏览器,在通知区域显示下载失败。我写的PDF与此code响应:

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?

推荐答案

,我猜想这是在响应POST。我有同样的问题,并找到<一href="http://stackoverflow.com/questions/15750012/android-browser-wont-download-pdf-file?rq=1#comment22429479_15750012">this在一个类似的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浏览器和海豚,这会导致下载到POST动作失败的错误。我改变了我的行动,以获得尽可能一种解决方法。

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 iterations on S/O; neither closing nor answering them all seems reasonable, so how about some links:

  • C# Response Shows Download Unsuccessful Error on Android Browser
  • C# Response.Write pdf not working with Android Browser
  • ASP.NET Inconsistent PDF file download results )

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

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