简体   繁体   English

Flex 3-从Flash发送HTTP Get请求,并希望Firefox显示“打开框”

[英]Flex 3 - Send a HTTP Get request from Flash and want Firefox to show Open With Box

I am a newb developer as far as Flex and Flash is concerned. 就Flex和Flash而言,我是一名新手开发人员。 This is what I'm trying to do: 这就是我想要做的:

1) Send a HTTP request to our server (with a custom made URL). 1)将HTTP请求发送到我们的服务器(带有自定义URL)。 The URL basically tells the server to send data in a CSV format. 该URL基本上告诉服务器以CSV格式发送数据。 2) The server sends a 200 OK response, which has Content-Type: application/csv and the payload is pure CSV data. 2)服务器发送200 OK响应,该响应具有Content-Type:application / csv,有效负载是纯CSV数据。

What I wish to do is, when firefox gets this 200 OK response, I want it to show the standard Open with box (the one that shows up when you download some file). 我想要做的是,当firefox收到200 OK响应时,我希望它显示标准的“打开方式”框(下载某些文件时显示的框)。

I tried doing this with HTTPService. 我尝试用HTTPService做到这一点。 I have a "Export to CSV" button on the flash component. 我在Flash组件上有一个“导出为CSV”按钮。 Upon clicking that, the flash component is able to succesfully send the HTTP request. 单击该按钮后,Flash组件便能够成功发送HTTP请求。 I however don't want Flash component to handle the response, so I don't have the 's "result" tag defined. 但是,我不希望Flash组件处理响应,因此我没有定义“结果”标签。 But nothing happens. 但是什么也没发生。 Any suggestions on how to do this. 有关如何执行此操作的任何建议。

You will need Flash to at least respond to the request, then you call navigateToURL to go to your file, something like this: 您将需要Flash至少响应请求,然后调用NavigationToURL转到文件,如下所示:

private function resultHandler(event:ResultEvent):void
{
    navigateToURL(new URLRequest('createdFile.csv','_self'));
}

Your server needs to send a header along with the file: 您的服务器需要将标头与文件一起发送:

Content-Disposition: attachment; filename=foo.csv

Edit: let's clarify that with an explanation: 编辑:让我们用一个解释来澄清一下:

When you do this: 执行此操作时:

navigateToURL(new URLRequest('foo.csv'), '_self');

You're indirectly actually asking the browser to get foo.csv. 您实际上是在间接要求浏览器获取foo.csv。 Now, in order for the browser to show the Save dialog, it needs to know the data should be treated as an attachment. 现在,为了使浏览器显示“保存”对话框,它需要知道数据应被视为附件。 The header: 标头:

Content-Disposition: attachment

accomplishes just that. 就做到了。 But often you also want to let the browser know the file name (and the file type, by way of the extension), which is why you add the filename bit after the semicolon. 但是通常您还希望让浏览器知道文件名(以及文件类型,通过扩展名),这就是为什么在分号后添加文件名位的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM