android客户端无法下载PDF的问题

jiejiep 2011-07-27 03:28:13

部门的一个项目,我的任务是负责为移动终端提供数据。
数据本来有PDF,TXT.DOC格式的文档,然后现在TXT的没问题,PDF的下载就出现异常。

代码如下:



WebClient wb = new WebClient( );

byte[] bytes = wb.DownloadData(attachFullName);

this._context.Response.Clear();
this._context.Response.BufferOutput = true;
this._context.Response.Buffer = false;
this._context.Response.Charset = "GB2312";
this._context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");

//通知浏览器下载文件而不是打开
//this._context.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(attCName, System.Text.Encoding.UTF8));
this._context.Response.AddHeader("Content-Disposition", "inline;filename=" + HttpUtility.UrlEncode(attCName, System.Text.Encoding.UTF8));
string fileType = attCName.EndsWith("txt") == true ? "txt" : attCName.EndsWith("pdf") == true ? "pdf" : attCName.EndsWith("doc") == true ? "word" : "pdf";
switch (fileType)
{
case "pdf":
{
this._context.Response.ContentType = "application/pdf";
break;
}
case "word":
{
this._context.Response.ContentType = "application/msword";
break;
}
case "txt":
default:
{
this._context.Response.ContentType = "text/plain";
break;
}
}
//this._context.Response.ContentType = "application/octet-stream";
this._context.Response.BinaryWrite(bytes);
this._context.Response.Flush( );
this._context.Response.Close( );



异常的详细信息是:

System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at WBS.KingtonNewsMobileWeb.NewsDetailsDownloadHandler.DownLoadFile()
at WBS.KingtonNewsMobileWeb.NewsDetailsDownloadHandler.ProcessRequest(HttpContext context)


在线等。。。急救啊。
...全文
325 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiejiep 2012-01-05
  • 打赏
  • 举报
回复
问题解决了。
有2个注意点:
1.iPhone的客户端和Android的客户端的处理方式有所不同。PDF的文件,iPhone可以直接打开,android就只能先下载。
2.WebClient下载文件时,设置格式为 GB2312
子夜__ 2011-07-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ling1212111 的回复:]

网上查了好多资料,也试了,没用啊。
[/Quote]
去移动开发哪儿问问。
jiejiep 2011-07-27
  • 打赏
  • 举报
回复
网上查了好多资料,也试了,没用啊。
子夜__ 2011-07-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ling1212111 的回复:]

还有一个这样的报错:

System.Web.HttpException: The remote host closed the connection. The error code is 0x80072746.
at System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.FlushCore(Byte[] status, Byte[] ……
[/Quote]
参考
jiejiep 2011-07-27
  • 打赏
  • 举报
回复
还有一个这样的报错:

System.Web.HttpException: The remote host closed the connection. The error code is 0x80072746.
at System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.FlushCore(Byte[] status, Byte[] header, Int32 keepConnected, Int32 totalBodySize, Int32 numBodyFragments, IntPtr[] bodyFragments, Int32[] bodyFragmentLengths, Int32 doneWithSession, Int32 finalStatus, Boolean& async)
at System.Web.Hosting.ISAPIWorkerRequest.FlushCachedResponse(Boolean isFinal)
at System.Web.HttpResponse.Flush(Boolean finalFlush)
at System.Web.HttpResponse.BinaryWrite(Byte[] buffer)
at WBS.KingtonNewsMobileWeb.NewsDetailsDownloadHandler.DownLoadFile()
at WBS.KingtonNewsMobileWeb.NewsDetailsDownloadHandler.ProcessRequest(HttpContext context)

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧