使用flex将参数传递给CGI脚本

时间:2013-03-16 08:28:34

标签: actionscript-3 flex3 cgi

我正在尝试将三个参数(arg1,arg2和arg3)传递给CGI脚本,但以下代码无效。

有人可以告诉我如何使用flex?

将参数传递给CGI脚本
public function loadURL():void {
    //frameBuffer.reloadFrame(frameBuffer.currentFrame); 
    var variables:URLVariables = new URLVariables("name=Franklin");
    var request:URLRequest = new URLRequest();
    request.url = "http://firefly.cs.missouri.edu/cgi-bin/main2.cgi?arg1=image.TIF&arg2=BranchPoints.txt&arg3=Medial.txt";
    request.method = URLRequestMethod.POST;
    request.data = variables;
    var loader:URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.addEventListener(Event.COMPLETE, completeHandler);
    try
    {
        loader.load(request);
    }
    catch (error:Error)
    {
        trace("Unable to load URL");
    }

    function completeHandler(event:Event):void
    {
        trace(event.target.data.welcomeMessage);
    }
    //Alert.show("Hi");
}

1 个答案:

答案 0 :(得分:0)

这样做:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
xmlns:mx="http://www.adobe.com/2006/mxml" 
layout="absolute" minWidth="955" minHeight="600" creationComplete="init(event)">

<mx:Script>
    <![CDATA[
        import mx.events.FlexEvent;

        public function loadURL():void 
        {
            var variables:URLVariables = new URLVariables();

            variables.name = "Franklin";
            variables.arg1 = "image.TIF";
            variables.arg2 = "BranchPoints.txt";
            variables.arg3 = "Medial.txt";

            var request:URLRequest = new URLRequest("http://firefly.cs.missouri.edu/cgi-bin/main2.cgi");
            request.method = "POST";
            request.data = variables;

            var loader:URLLoader = new URLLoader();
            loader.dataFormat = URLLoaderDataFormat.TEXT;
            loader.addEventListener(Event.COMPLETE, completeHandler);
            loader.addEventListener(IOErrorEvent.IO_ERROR, onError);

            loader.load(request);
        }

        private function completeHandler(event:Event):void
        {
            trace(event.target.data.welcomeMessage);
        }

        private function onError(event:IOErrorEvent):void
        {
            trace("Fault!");
        }

        protected function init(event:FlexEvent):void
        {
            loadURL();
        }

    ]]>
</mx:Script>

</mx:Application>

该脚本给了我以下代码:

<html><head><title>My First Script</title></head>
<body>
<p>Hello world!</p>
</body></html>image.TIFBranchPoints.txtMedial.txtimage.TIF BranchPoints.txt Medial.txt