使用正则表达式,您可以将输出转换为下划线。这种方法利用了以下事实:
URLRequest
的data
变量是泛型的Object
String
是一个Object
toString()
和的输出replace()
是String
对象 3。
编码:
var url:String = "http://www.[yourDomain].com/test";
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables("my_user_name=f_o_o");
// add some more variables:
variables.exampleSessionId = "test";
variables.example_Session_Id2 = "test2";
// set up the search expression:
var undPatrn:RegExp = /%5f/gi;
trace("Without '_': " + variables.toString());
trace("With '_': " + variables.toString().replace(undPatrn, "_"));
trace(variables);
// navigate with %5f:
request.data = variables.toString();
navigateToURL(request);
// navigate with underscore:
request.data = variables.toString().replace(undPatrn, "_");
navigateToURL(request);