Packageco.uk.mikestead.net
Classpublic class URLRequestBuilder

The URLRequestBuilder class takes an instance of URLVariables and wraps these variables in a URLRequest with the appropriate HTTP encoding. This class is needed to build URLRequest objects with encodings not automatically applied when the URLRequest.data property is set.

To determine the correct encoding to apply, each variable in the URLVariables instance is examined. If a variable of type URLFileVariable is found then the encoding is set to multipart/form-data, and the URLRequest.method set to POST. If no URLFileVariable is found then the URLRequest.data property is set with the URLVariables instance directly. To see the encoding used in this case refer to the documentation for the URLRequest.data property

.


Example
     // Construct variables (name-value pairs) to be sent to sever
     var variables:URLVariable = new URLVariables();
     variables.userImage = new URLFileVariable(jpegEncodedData, "user_image.jpg");
     variables.userPDF = new URLFileVariable(pdfEncodedData, "user_doc.pdf");
     variables.userName = "Mike";
     // Build the request which houses these variables
     var request:URLRequest = new URLRequestBuilder(variables).build();
     request.url = "some.web.address.php";
     // Create the loader and use it to send the request off to the server
     var loader:URLLoader = new URLLoader();
     loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
     loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onError);
     loader.addEventListener(IOErrorEvent.IO_ERROR, onError);
     loader.addEventListener(Event.COMPLETE, onServerResponse);
     loader.load(request);
     function onServerResponse(event:Event):void
     {
         trace("Variables uploaded successfully");
     }
     function onError(event:Event):void
     {
         trace("An error occurred while trying to upload data to the server: \n" + event);
     }
     

See also

URLFileVariable


Public Methods
 MethodDefined by
  
URLRequestBuilder(variables:URLVariables)
Constructor.
URLRequestBuilder
  
build():URLRequest
Build a URLRequest instance with the correct encoding given the URLVariables provided to the constructor.
URLRequestBuilder
Constructor detail
URLRequestBuilder()constructor
public function URLRequestBuilder(variables:URLVariables)

Constructor.

Parameters
variables:URLVariables — The URLVariables to encode within a URLRequest.
Method detail
build()method
public function build():URLRequest

Build a URLRequest instance with the correct encoding given the URLVariables provided to the constructor.

Returns
URLRequest — URLRequest instance primed and ready for submission