A helpful utility class that is used to create and handle basic HTTP requests in Flash and AIR.
Example
var args:Object = new Object();
args.foo = "bar";
args.format = "xml";
var callback:Object = new Object();
callback.success = handleSuccess;
callback.failure = handleFailure;
Connection.asyncRequest("GET", "http://example.com/some_feed.xml", callback, args);
function handleSuccess(response:Object):void
{
trace(response.responseText);
var xml:XML = response.responseXML; // grab the parsed xml object.
}
function handleFailure(response:Object):void
{
trace(response.responseText);
}
public static function asyncRequest(httpMethod:String, url:String, callback:Object, args:Object = null, headers:Array = null):URLRequest
Creates and sends a new HTTP request.
Parameters
| httpMethod:String — The URLRequestMethod to use in the request.
|
| |
| url:String — The URL to call in the URLRequest
|
| |
| callback:Object — An Object containing success, failure and security callback functions.
|
| |
| args:Object (default = null) — An Object, String, URLVariables or ByteArray to include in the URLRequest.data object.
|
| |
| headers:Array (default = null) — An array of valid URLRequestHeader objects to be set in the URLRequest.requestHeaders property.
|
Returns
| URLRequest — The URLRequest object generated.
|
public static function http_build_query(args:Object, separator:String = "&"):String
Generates URL-encoded query string given an object containing key value pairs.
Parameters
| args:Object — An object containing the key-value pairs.
|
| |
| separator:String (default = "&") — A string containing the characters used to seperate each element of the query string.
|
Returns
public static function isValidXML(xml:XML):Boolean
Checks if the provided XML object represents a valid XML document.
Parameters
| xml:XML — An XML object, typically as XML(responseText) to validate as XML
|
Returns
public static function parse_query(query:String, separator:String = "&"):Object
Parses a query string into a native object containing key value pairs.
Parameters
| query:String — The query string to parse to a native object.
|
| |
| separator:String (default = "&") — The seperator used to split the string into seperate elements.
|
Returns