如何在Action Script中将二进制内容发送到servlet

时间:2014-11-10 14:14:39

标签: java actionscript-3 flash actionscript

我在一个文件中有一个动作脚本函数,它将一个pdf文件作为二进制内容发送到一个servlet,如下所示。

private function savePDF(pdfBinary:ByteArray, urlString:String):void{

            try{
                Alert.show("in savePDF urlString" +urlString);
                //result comes back as binary, create a new URL request and pass it back to the server
                var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");

                var sendRequest:URLRequest = new URLRequest(urlString);
                sendRequest.requestHeaders.push(header);
                sendRequest.method = URLRequestMethod.POST;
                sendRequest.data = pdfBinary;

                Alert.show("in savePDF calling sendToURL"); 

                sendToURL(sendRequest);
            }catch(error:*){
                Alert.show("in savePDF err" +error);    
                trace(error);
                }
            } 

此代码适用于flashplayers版本,如10,11,13

但是在14.0.0.126或更高版本的更高版本的flashplayers中失败了。

我收到以下错误

SecurityError: Error #3769: Security sandbox violation: Only simple headers can be used with navigateToUrl() or sendToUrl().

有关如何解决此问题的任何建议?

1 个答案:

答案 0 :(得分:2)

您可以尝试使用URLLoader代替sendToURL()

Alert.show("in savePDF urlString" +urlString);
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");

var sendRequest:URLRequest = new URLRequest(urlString);
sendRequest.requestHeaders.push(header);
sendRequest.method = URLRequestMethod.POST;
sendRequest.data = pdfBinary;

Alert.show("in savePDF calling URLLoader"); 

var loader:URLLoader = new URLLoader();
loader.load(sendRequest);