与POST AS3错误,但无法与GET(#2032流错误) [英] AS3 Error with POST but not with GET (#2032 Stream Error)
本文介绍了与POST AS3错误,但无法与GET(#2032流错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
本的应的简单。我想POST数据发送到服务器,并编写了定制包装如下:
包com.cron {
进口flash.events。*
进口flash.net。*
公共类邮件{
HTTP:// WWW [MYDOMAIN] .COM /脚本/ flashmail.phpVAR在scriptUrl =;
VAR通=[输入mypassword]
VAR产品名称='[myProduct的]
VAR fromemail ='noreply @ MYDOMAIN] .COM
VAR scriptLoader,scriptRequest,scriptVars,的onComplete
公共职能邮件(产品名称= NULL,Fromemail = NULL,的onComplete = NULL,在scriptUrl = NULL,通= NULL){
//设置PARAMS:
在scriptUrl =(在scriptUrl在scriptUrl:在scriptUrl)
产品名称=(产品名称产品名称:产品)
fromemail =(?Fromemail Fromemail:fromemail)
通过=(合格合格:通)
的onComplete =的onComplete?的onComplete:空
//设置类:
scriptRequest =新的URLRequest(在scriptUrl);
scriptLoader =新的URLLoader();
scriptVars =新的URLVariables();
}
公共职能的sendmail(toemail,主题,味精){
scriptLoader.addEventListener(引发Event.COMPLETE,handleLoadSuccessful);
scriptLoader.addEventListener(IOErrorEvent.IO_ERROR,handleLoadError);
scriptLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS,handleLoadError);
scriptVars.pass =通;
scriptVars.productname =产品名称;
scriptVars.toemail = toemail;
scriptVars.subject =主体;
scriptVars.msg =味精;
scriptVars.fromemail = fromemail;
//跟踪(scriptVars)
scriptRequest.method = URLRequestMethod.POST;
scriptRequest.data = scriptVars;
G.traceObj(scriptRequest)
scriptLoader.load(scriptRequest);
跟踪(MAIL:发送邮件至+ toemail)
}
私有函数handleLoadSuccessful($ EVT:事件):无效{
如果(字符串(scriptLoader.data)!='1'){
跟踪(MAIL:错误与脚本:)
跟踪(scriptLoader.data)
如果(的onComplete)的onComplete(0);
返回;
}其他{
跟踪('MAIL:发送成功)
如果(的onComplete)的onComplete(1);
}
}
私有函数handleLoadError($ EVT):无效{
跟踪(MAIL:连接失败,出现错误:+ $ EVT);
如果(的onComplete)的onComplete(0);
}
}
}
如果我修改 URLRequestMethod.POST
到 URLRequestMethod.GET
,这一切的伟大工程。然而,使用POST,我得到以下错误:
MAIL:连接失败,出现错误:[HTTPStatusEvent TYPE =则httpStatus泡沫=假可取消=假的EventPhase = 2状态= 0 responseURL = NULL]
MAIL:连接失败,出现错误:[IOErrorEvent TYPE =ioError在泡沫=假可取消=假的EventPhase = 2文本=错误#2032:流错误网址:HTTP:// WWW [myDomain的]的.com /脚本/ flashmail .PHP]
Bizzarely,如果我上传这对我的服务器,它工作正常!它只是拒绝与本地SWF或打包AIR应用程序的工作。 我需要部署的在Android 所以它的重要,我得到它在本地工作。
解决方案
btn.addEventListener(MouseEvent.CLICK,处理程序);
函数处理程序(事件:MouseEvent)方法:无效
{
VAR URL:的URLLoader =新的URLLoader();
url.dataFormat = URLLoaderDataFormat.VARIABLES;
VAR要求:的URLRequest =新的URLRequest(HTTP:// WWW [myDomain的]的.com /脚本/ flashmail.php);
VAR RV:使用URLVariables =新的URLVariables();
rv.user_ = user_.text;
request.data = RV;
request.method = URLRequestMethod.POST;
url.load(要求);
url.addEventListener(引发Event.COMPLETE,eventComplete);
url.addEventListener(IOErrorEvent.IO_ERROR,IO错误);
功能eventComplete(五:事件):无效
{
如果(e.target.data.success ==OK)
{
跟踪(结果:+ e.target.data.success2);
}
其他
{
跟踪('没有结果');
}
}
}
功能IO错误(五:事件):无效
{
跟踪(连接错误);
}
This should be simple. I'm trying to send POST data to a server and have written a custom package for it as follows:
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);
}
}
}
If I change URLRequestMethod.POST
to URLRequestMethod.GET
, this all works great. However, using POST, I get the following errors:
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, if I upload this to my server, it works fine! It just refuses to work with a local swf or packaged AIR app. I need to deploy this on Android so it's crucial I get it working locally.
解决方案
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");
}
这篇关于与POST AS3错误,但无法与GET(#2032流错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文