ActionScript 3 AS3:使用POST发送数据

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3:使用POST发送数据相关的知识,希望对你有一定的参考价值。

var bg_mc:MovieClip = new MovieClip();
	bg_mc.graphics.beginFill(0xFF0000, 1);
	bg_mc.graphics.drawRect(0, 0, 100, 100);
	bg_mc.graphics.endFill();
	bg_mc.x = stage.stageWidth / 2 - bg_mc.width / 2;
	bg_mc.y = stage.stageHeight / 2 - bg_mc.height / 2 ;
	bg_mc.buttonMode = true;
	bg_mc.addEventListener(MouseEvent.MOUSE_DOWN, visitSite);
addChild(bg_mc);

function visitSite(e:MouseEvent):void {
	var url:String = "http://api.flickr.com/services/rest/";
	var request:URLRequest = new URLRequest(url);
	var requestVars:URLVariables = new URLVariables();
		requestVars.api_key = "3c84c0ca7f9ae17842a370a3fbc90b63";
		requestVars.method = "flickr.test.echo";
		requestVars.format = "rest";
		requestVars.foo = "bar";
		requestVars.sessionTime = new Date().getTime();
		request.data = requestVars;
		request.method = URLRequestMethod.POST;
	
	var urlLoader:URLLoader = new URLLoader();
		urlLoader = new URLLoader();
		urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
		urlLoader.addEventListener(Event.COMPLETE, loaderCompleteHandler, false, 0, true);
		urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler, false, 0, true);
		urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler, false, 0, true);
		urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true);
	for (var prop:String in requestVars) {
		//trace("Sent: " + prop + " is: " + requestVars[prop]);
	}
	try {
		urlLoader.load(request);
	} catch (e:Error) {
		trace(e);
	}
}
function loaderCompleteHandler(e:Event):void {
	var responseVars = URLVariables( e.target.data );
	trace( "responseVars: " + responseVars );
	
}
function httpStatusHandler( e:HTTPStatusEvent ):void {
	//trace("httpStatusHandler:" + e);
}
function securityErrorHandler( e:SecurityErrorEvent ):void {
	trace("securityErrorHandler:" + e);
}
function ioErrorHandler( e:IOErrorEvent ):void {
	//trace("ORNLoader:ioErrorHandler: " + e);
	dispatchEvent( e );
}

以上是关于ActionScript 3 AS3:使用POST发送数据的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 使用AS3绘制一个矩形

ActionScript 3 AS3:在ActionScript中使用E4X生成动态XML

ActionScript 3 使用Blitting的AS3动画

ActionScript 3 在AS3中使用麦克风

ActionScript 3 使用AS3读取不同的文件类型

ActionScript 3 AS3使用RegExp检查数字和字母