Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs

Sun, May 9, 2010

Programming

It was nice enough in AS2 when you did a simple LoadVars object to get the data from a server side page :

var lv:LoadVars = new LoadVars();
lv.username = "ruliman";
lv.password = "123456";
lv.sendAndLoad("somefile.php",lv,"POST");
All I had to do is print on my php something like:
&message=something&var1=somethingelse&

where I was starting with & and ending with & , using name value pairs.

it Was simple , straight forward and everybody got used to it, from Flash designers to php programmers.

In AS3 though things are different.

var variables:URLVariables = new URLVariables();
variables.username = "ruliman";
variables.password= "123456";
//
trace(variables.toString());
var request:URLRequest = new URLRequest("somefile.php");
request.method = URLRequestMethod.POST;
request.data = variables;

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;

try{
loader.load(request);
}
catch (error:Error) {
trace("Unable to load URL");
}

First you need to STOP starting and ending with &.
You dont need that and in fact , you will get the above error, leaving you wondering why on earth this is not working

so from AS2 where in php you printed

print "&message=something&var1=somethingelse&";
now you need to print

print "message=".urlencode(something)."&var1=".urlencode(somethingelse);

so you loose the & in the beginning and in the end plus you make sure all returned data (apart from variables names) are urlencoded.
Adobe should at least MAKE A DAMN NOTE on this new way of handling the returned data from a url posted page...

Share
, , ,

This post was written by:

- who has written 196 posts on ropox.net.

Software Engineer and Web Developer, keen on new technologies and has passion for web engineering.... Internet is my job and i love it...!!! Founded Baldpixel (baldpixel.com) on 2008 which is specialized on enginnering custom web projects while cooperating with top advertising agencies on the net.

Contact the author