views:

283

answers:

4

I get 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?

A: 

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

Valentin
A: 

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.

Juan Pablo Califano
+3  A: 

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.

shure
A: 

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.

Fahim Chowdhury