URL string AS3 & # 8594; URLRequest

I use some bootloader that does not accept products.php?cat=10 as the target, because it is too stupid to figure out what the file name is and what the query string is. Is there an AS3 function that will parse the URL and return a URLRequest based on the variables in the query string?

+4
source share
3 answers

It is possible to create everything you need:

 import flash.net.URLRequest; import flash.net.URLLoader; import flash.net.URLVariables; import flash.net.URLRequestMethod; import flash.events.Event; // the path to the backend file var url : String = 'http://youdomain.com/filepath.php'; // url variables all which will appear after ? sign var urlVariables : URLVariables = new URLVariables (); urlVariables['varname'] = 'varvalue'; urlVariables['varname1'] = 'varvalue1'; // here you can add as much as you need // creating new URL Request // setting the url var request : URLRequest = new URLRequest ( url ); // setting the variables it need to cary request.data = urlVariables; // setting method of delivering variables ( POST or GET ) request.method = URLRequestMethod.GET; // creating actual loader var loader : URLLoader = new URLLoader (); loader.addEventListener( Event.COMPLETE, handleLoaderComplete ) loader.load ( request ); 
+8
source

You can use URLVariables.decode () to convert the query string to the properties of the URLVariables object:

 function getProperURLRequest ( url : String ) : URLRequest { var input : Array = url.split("?"); var urlVars : URLVariables = new URLVariables (); urlVars.decode( input[1] ); var urlReq : URLRequest = new URLRequest ( input[0] ); urlReq.data = urlVars; urlReq.method = URLRequestMethod.GET; return urlReq; } 
+5
source

There should be no problem with URLs like products.php?cat=1 . Perhaps you just forgot to put crossdomain.xml on your server. I suppose this is the most common mistake when using URLRequest

0
source

All Articles