6
votes

I get the following error when trying to pass variables via URLRequestMethod.POST;

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

Is there a method for string URL Encoding?

4

4 Answers

21
votes

There are escape() and unescape() as top level functions of ActionScript 3 for URL encoding/decoding.

7
votes

Solution to this problem is: You have to set URLLoaderDataFormat to URLLoaderDataFormat.TEXT not URLLoaderDataFormat.VARIABLES. Because VARIABLES means different types of data, not multiple items in URLVariables.

6
votes

That error message is generally caused by passing a non valid querystring to an URLVariables object. But you don't need to pass the querystring in most cases. You can just add pairs to the object as regular properties and let it do the encoding and escaping (which is what this class is meant to do).

var vars:URLVariables = new URLVariables();
vars.param1 = "Text to be escaped. Works for non ascii: ñ";
vars.param2 = "http://www.google.com/?q=something&test=1234";
trace(vars.toString());

The trace, of course, is not necessary, it's just so you can see that the encoding worked.

0
votes

I came across this problem many times and usually its the myLoader.dataFormat = URLLoaderDataFormat.VARIABLES line which I missed out. Try to remove this line if you have it:

request.method = URLRequestMethod.POST

and finally make sure you are receiving a response through a variable theStatus=okay then that should do the trick.