我有一个 Flex 应用程序,它在我们的网络服务器上调用一个 .aspx 页面,该页面构建一个 PDF 或 Excel 文件。现在,我正在使用 navigateToURL() 来调用该文件,并且在成功构建输出文件时可以正常工作。但是,如果出现错误或超时,则无法在 Flash 影片中知道这一点。
我正在尝试使用 URLLoader,以便我可以侦听 HTTP 状态代码,并知道加载何时完成,但是,URLLoader 只是返回位图数据,没有任何提示用户打开或保存输出文件。有没有办法做到这一点?
这是我的 ActionScript 代码的两个版本:
private function buildFile():void
{
var variables:URLVariables = new URLVariables();
variables.rptName = "report1";
variables.rptFormat = "PDF";
var request:URLRequest = new URLRequest();
request.url = "/buildFile.aspx";
request.method = URLRequestMethod.POST;
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS,
httpStatusHandler);
loader.load(request);
}
private function buildFile():void
{
var variables:URLVariables = new URLVariables();
variables.rptName = "report1";
variables.rptFormat = "PDF";
var request:URLRequest = new URLRequest();
request.url = "/buildFile.aspx";
request.method = URLRequestMethod.POST;
request.data = variables;
navigateToURL(request, "_self");
}
仅供参考,这是当前输出 PDF 或 Excel 文件的代码块:
System.Web.HttpContext httpC;
httpC = System.Web.HttpContext.Current;
httpC.Response.Clear();
httpC.Response.ClearHeaders();
httpC.Response.Expires = 0;
switch (ReportFormat)
{
case "Excel": Response.ContentType = "application/vnd.ms-excel"; break;
case "PDF": Response.ContentType = "application/pdf"; ; break;
}
Response.AddHeader("Content-disposition", "attachment;filename=" + fileName);
BinaryWriter binaryWriter = new BinaryWriter(httpC.Response.OutputStream);
binaryWriter.Write(result);