问题
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?
回答1:
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
.
回答2:
There are escape() and unescape() as top level functions of ActionScript 3 for URL encoding/decoding.
回答3:
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.
回答4:
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.
来源:https://stackoverflow.com/questions/3487479/url-encode-variable-in-as3