Cheat sheet: Flash Player HTTP talking with HTTPService, URLLoader and friends



HTTPService URLLoader Loader FileReference MultipartURLLoader

mx.rpc.http.HTTPService
mx.rpc.http.mxml.HTTPService
flash.net.URLLoader flash.display.Loader
flash.net.FileReference
ru.inspirit.net.MultipartURLLoader
Sending format






httpService.contentType=
URLRequest.data= - -
-
Text (variables) string
-
-
x
XML HTTPService.CONTENT_TYPE_XML - -
-
x
Binary
- data as ByteArray - fileReference.load() to load a local file x
Image - 1) -
fileReference.load() to load a local image
1)
HTML form -
-
-
- (FileReference sends files in HTML form)
x
URL-encoded variables HTTPService.CONTENT_TYPE_FORM URLVariables -
-
x
HTTP headers





Send
only for POST requests: urlRequest.requestHeaders=[new URLRequestHeader()] 3)
only for POST requests: urlRequest.requestHeaders=[new URLRequestHeader()] 3)
only for POST request: urlRequest.requestHeaders=[new URLRequestHeader()] 3) addHttpHeader() 3)
Receive 4) -
-
-
-
-
HTTP Method

httpService.method= urlRequest.method=
urlRequest.method= urlRequest.method=
GET HTTPRequestMessage.GET_METHOD URLRequestMethod.GET
URLRequestMethod.GET URLRequestMethod.GET -
POST
HTTPRequestMessage.POST_METHOD URLRequestMethod.POST URLRequestMethod.POST URLRequestMethod.POST x
PUT -
-
-
-
-
DELETE -
-
-
-
-
Other
Tokens AsyncToken
-
-
-
-
Follows HTTP Redirects ?




HTTP status -
-
-
-
-
Events

only loader.contentLoaderInfo dispatches events:

Errors






httpService.send(parameters)
For POST request, parameters must be non null. Otherwise, the method is changed to GET.
try {
    urlLoader.load(urlRequest)
} catch(e:SecurityError){}
} catch(e:ArgumentError){}
} catch(e:TypeError){}
} catch(e:MemoryError){}
try {
    loader.load(urlRequest, loaderContext)
catch (e:IOError) {}
catch (e:SecurityError) {}

 - If uploading a file, it must be initiated by user event.
- Don't reuse the instance of loader.
try {
    fileReference.upload(urlRequest)
} catch(e:SecurityError){}
} catch(e:ArgumentError){}
} catch(e:IllegalOperationError){}
} catch(e:MemoryError){}

Receiving format






httpService.resultFormat = urlLoader.dataFormat=


Text
HTTPService.RESULT_FORMAT_TEXT URLLoaderDataFormat.TEXT -


XML
HTTPService.RESULT_FORMAT_E4X -
-


Binary
-
URLLoaderDataFormat.BINARY -


Image (jpg, png, gif) -
2)
x
2)

swf files
-
-
x


URL variables
HTTPService.RESULT_FORMAT_OBJECT URLLoaderDataFormat.VARIABLES


Received data







var resultXML:XML = urlLoader.data as XML

try {
    fileReference.save(data, defaultFileName)
} catch(e:IllegalOperationError){}
} catch(e:ArgumentError){}
} catch(e:Error){}
} catch(e:MemoryError){}


1) Bitmaps created in Flash Player can be encoded with e.g. PNGEncoder from corelib and sent with these classes.
2) The image can be loaded as binary, converted by e.g. JPGEncoder and displayed.
3) Depending on the Flash Player version, different HTTP headers are blocked. See Adobe KB for complete list and an article about the authorization header.
4) Flash Player cannot receive HTTP headers.

General remarks



//TODO

 





This work is licensed under a Creative Commons Attribution 2.5 Switzerland License
by Faindu, the creator of BlocStac.com.