6

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 Answers 4

21

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

Sign up to request clarification or add additional context in comments.

1 Comment

Also useful are encodeURIComponent and decodeURIComponent if you want to encode separators.
7

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.

Comments

6

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.

1 Comment

This helped med with another problem I had. Thanks.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.