Variable URL encoding in AS3?

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

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

Is there a way to encode a URL string?

+6
flash actionscript-3 urlencode
source share
4 answers

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

+7
source share

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

+21
source share

This error message is usually caused by passing an invalid query string to the URLVariables object. But in most cases you do not need to pass the request. You can simply add pairs to the object as normal properties and let it perform encoding and escaping (which this class should 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()); 

Tracing, of course, is not needed, so you can see that the encoding is working.

+6
source share

I encountered this problem many times and usually its line is myLoader.dataFormat = URLLoaderDataFormat.VARIABLES , which I missed. Try deleting this line if you have one:

 request.method = URLRequestMethod.POST 

and finally make sure you get the answer through theStatus=okay variable, then this should do the trick.

0
source share

All Articles