Flash & ActionScript3: URLLoader POST example

Trabla: Flash & ActionScript3 - URLLoader POST example

Solving:

import flash.net.URLLoader ;
import flash.net.URLRequest ;
...

// byteArrayData - byte array with data, e.g. wav file

var serviceUrl:String = 'http://myservice.com/dosomething?id=1&mode=2';
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest( serviceUrl );

loader.addEventListener( Event.COMPLETE, onResponse);
request.method = URLRequestMethod.POST;
request.data = byteArrayData;
loader.load(request);

...

public function onResponse( e:Event ):void
{
      trace('Response:' + e.target.data );
}

No comments:

Post a Comment