0

应该很简单。我正在尝试将 POST 数据发送到服务器并为其编写了一个自定义包,如下所示:

package com.cron {
import flash.events.*
import flash.net.*

public class Mail {
    var scriptURL = "http://www.[mydomain].com/scripts/flashmail.php";
    var pass = '[mypassword]'
    var productName = '[myProduct]'
    var fromemail = 'noreply@[mydomain].com'
    var scriptLoader,scriptRequest,scriptVars,onComplete

    public function Mail(ProductName=null, Fromemail=null, OnComplete=null, ScriptURL=null, Pass=null) {
        //SET PARAMS:
        scriptURL = (ScriptURL ? ScriptURL : scriptURL)
        productName = (ProductName ? ProductName : productName)
        fromemail = (Fromemail ? Fromemail : fromemail)
        pass = (Pass ? Pass : pass)
        onComplete = OnComplete ? OnComplete : null
        //SETUP CLASS:
        scriptRequest = new URLRequest(scriptURL);
        scriptLoader = new URLLoader();
        scriptVars = new URLVariables();
    }

    public function sendmail(toemail,subject,msg){
         
        scriptLoader.addEventListener(Event.COMPLETE, handleLoadSuccessful);
        scriptLoader.addEventListener(IOErrorEvent.IO_ERROR, handleLoadError);
        scriptLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, handleLoadError);
         
        scriptVars.pass = pass;
        scriptVars.productname = productName;
        scriptVars.toemail = toemail;
        scriptVars.subject = subject;
        scriptVars.msg = msg;
        scriptVars.fromemail = fromemail;
        //trace(scriptVars)

        scriptRequest.method = URLRequestMethod.POST; 
        scriptRequest.data = scriptVars;

        G.traceObj(scriptRequest) 

        scriptLoader.load(scriptRequest);
        trace("MAIL: Sending mail to "+toemail)
    }

    private function handleLoadSuccessful($evt:Event):void{
        if(String(scriptLoader.data) != '1'){
            trace("MAIL: Error with script:")
            trace(scriptLoader.data)
            if(onComplete) onComplete(0);
            return;
        }else{
            trace('MAIL: Sent successfully')
            if(onComplete) onComplete(1);
        }

    }
     
    private function handleLoadError($evt):void{
        trace("MAIL: Connection Failed with error: "+$evt);
        if(onComplete) onComplete(0);
    }
}

}

如果我URLRequestMethod.POST改为URLRequestMethod.GET,这一切都很好。但是,使用 POST,我收到以下错误:

MAIL: Connection Failed with error: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=0 responseURL=null]
MAIL: Connection Failed with error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://www.[myDomain].com/scripts/flashmail.php"]

奇怪的是,如果我将它上传到我的服务器,它工作正常!它只是拒绝使用本地 swf 或打包的 AIR 应用程序。我需要在 Android 上部署它,所以让它在本地工作至关重要。

4

1 回答 1

0
btn.addEventListener(MouseEvent.CLICK,handler);
function handler(event:MouseEvent):void
{
        var url:URLLoader = new URLLoader();
        url.dataFormat = URLLoaderDataFormat.VARIABLES;
        var request:URLRequest = new URLRequest("http://www.[myDomain].com/scripts/flashmail.php");
        var rv:URLVariables = new URLVariables();
        rv.user_ = user_.text;
        request.data = rv;
        request.method = URLRequestMethod.POST;
        url.load(request);
        url.addEventListener(Event.COMPLETE,eventComplete);
        url.addEventListener(IOErrorEvent.IO_ERROR,ioerror);
        function eventComplete(e:Event):void
        {
            if (e.target.data.success == "ok")
            {
                trace('result:' + e.target.data.success2);
            }
            else
            {
                trace('no result');
            }
        }
}
function ioerror(e:Event):void
{
    trace("Connection Error");
}
于 2013-10-19T19:52:06.130 回答