这个应该很简单。我正在尝试将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"]
Bizzarely,如果我将它上传到我的服务器,它工作正常!它只是拒绝使用本地swf或打包的AIR应用程序。 我需要在Android上部署,因此我必须让它在本地运行。
答案 0 :(得分: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");
}