View Single Post
Nutrox's Avatar Nutrox Nutrox is offline Super Moderator 17 Creative Assets 2008-11-13 #14 Old  
Ok, it seems that the browser WILL automatically decompress incoming data if the Content-Encoding header sent from the server is "gzip" or "deflate". This happens with IE6, Firefox, and all modern browsers because they automatically send an Accept-Encoding header with every request telling the server they can handle gzip and deflate encoded data. If you set the Accept-Encoding header in Flash I think it will overwrite the default one sent by the browser (I need to confirm that), so you shouldn't really need to send that header.

One thing to keep in mind, if you do not pass any data to the server with the request you send from Flash it will default to GET and will not send any headers. So, you must send data with POST requests even if it is an empty byte array.

Code:
request.method = URLRequestMethod.POST;
request.data = new ByteArray(); // required for POST requests
If you are testing things from a local server then you must always make sure you send Content-Encoding headers with the response data.

So to wrap things up, if the service you are using is sending the response as gzip encoded data then you don't need to do anything in Flash, the data will automatically be converted to text (if running from a browser). If you are running the SWF from the Flash IDE then you will need to send the Accept-Encoding header with the requests and also decompress the data when it is loaded into Flash. No browser, no automatic decompression.

You can save yourself a load of hassle though by using zlib compression, browsers won't attempt to decompress zlib data.

It will be interesting to find out how AIR handles all of this, so I will look into that today at some point.
Reply With Quote