Skip to content
cristobal edited this page Nov 22, 2010 · 5 revisions

Description

HTTPService for AS3 tries to mimic the mx.rpc.http.HTTPService behaviour for AS3 only classes.
It does so by wrapping the flash.net.URLLoader & flash.net.URLRequest classes as it where one class.

Example

Using the class to load xml should be as simple as:

import com.net.http.HTTPService;
import com.net.rpc.events.ResultEvent;
import com.net.rpc.events.FaultEvent;

/**
 * Complete handler
 */
function handleComplete(result:ResultEvent):void {
  trace("Successfully loaded xml:");
  trace(event.result);
}

/**
 * Fault handler
 */
function handleFault(event:FaultEvent):void {
  trace("Could not load xml");
  trace(event.fault);
}

/* Initialize and set parameters*/
var httpService:HTTPService = new HTTPService();
httpService.url = "http://example.com/destination";
httpService.method = HTTPService.REQUEST_METHOD_POST; // Default is HTTPService.REQUEST_METHOD_GET 
httpService.resultFormat = HTTPService.RESULT_FORMAT_XML;

/* Add Event listeners */
httpService.addEventListener(ResultEvent.RESULT, handleComplete);
httpService.addEventListener(FaultEvent.Fault, handleFault);

/*  Send the request */
httpService.send({"key": "value"});

Limits

Only result format for XML and Text are supported, since this are the forma supported by the URLRequest Class.
It should be possible to implement JSON and other formats by adding additional parsers but it’s not done for this implementation.

Clone this wiki locally