package com.ericfeminella.net
{
import com.ericfeminella.utils.AbstractStaticType;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import mx.rpc.IResponder;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
/**
*
* Provides an all static API for posting name / value pairs
* to a specifed URI
*
* @see flash.net.URLVariables
* @see mx.rpc.IResponder
*
*/
public final class HTTPPOSTGateway extends AbstractStaticType
{
/**
*
* Posts a series of name / value pairs to a specified URI in
* a URL encoded query string
*
* @param URI in which the values are to be posted
* @param arbitrary object consisting of name / value pairs
* @param an object which implements <code>IResponder</code>
*
*/
public static function post(uri:String, rawData:Object, responder:IResponder) : void
{
var nameValuePairs:URLVariables = new URLVariables();
for (var name:String in rawData)
{
nameValuePairs[name] = rawData[name];
}
var request:URLRequest = new URLRequest( uri );
request.method = URLRequestMethod.POST;
request.data = nameValuePairs;
var loader:URLLoader = new URLLoader();
loader.addEventListener( ResultEvent.RESULT, responder.result );
loader.addEventListener( FaultEvent.FAULT, responder.fault );
loader.load( request );
}
}
}