author: Krasimir Tsonev

Hi there, I'm . Senior front-end engineer with over 13 years of experience. I write, speak and occasionally code stuff. Follow me on Twitter, GitHub, Facebook or LinkedIn

A strange IOErrorEvent.IO_ERROR event dispatched

Really simple GET request from a flex based application. However it fails if GET parameters are passed.

var obj:Object = {property: "value"};
var urlString:String = "" + JSON.encode(obj);
var urlRequest:URLRequest = new URLRequest(urlString);
urlRequest.method = URLRequestMethod.GET;
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, complete);
urlLoader.addEventListener(ProgressEvent.PROGRESS, progress);
urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityError);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, IOError);

In the above example *IOError* is called. I firstly checked for *crossdomain.xml* on the server, because sometimes that cause such problems. Unfortunately there was crossdomain policy file, so the problem was somewhere else. I removed *JSON.encode(obj)* from the url and everything was ok. The problem was that the passed json encoded string wasn't urlencoded. Here is the fix:

var urlString:String = "" + escape(JSON.encode(obj));
If you enjoy this post, share it on Twitter, Facebook or LinkedIn. Or maybe comment below: