2013-10-17 73 views
0

應該應該很簡單。我試圖發送POST數據到服務器併爲其如下寫了一個自定義包:AS3錯誤與POST但不與GET(#2032流錯誤)

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 = '[email protected][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.POSTURLRequestMethod.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"] 

Bizzarely,如果我上傳這個到我的服務器,它工作正常!它只是拒絕使用本地swf或打包的AIR應用程序。 我需要在Android上進行部署,所以關鍵是我在本地工作。

+0

什麼是[Mydomain]在這裏?它是一個有效的域名? – Zeus

+0

是的,這只是我的服務器。當我切換到GET – cronoklee

+0

ok時,此確切腳本完美工作正常首先,您需要將文件夾添加到[Truested Location Settings]中的受信任位置(http://help.adobe.com/zh_CN/FlashPlayer/LSM/WS6aa5ec234ff3f285139dc56112e3786b68c-7ff0.html )其中包含您的SWF ...第二你的flashMail.php應該也處理POST數據,但看起來像它...但是,我希望它是處理有效的方式 –

回答

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"); 
} 
相關問題