Aaaargh! No matter what I do, I always get the same error:
Error opening URL ‘http://www.mydomain.com/return.php’
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at flash.net::URLLoader/onComplete()
Here’s my code:
var urlVariables:URLVariables = new URLVariables()
urlVariables.test1 = 'bacon';
urlVariables.test2 = 'kittens';
var urlRequest:URLRequest=new URLRequest('http://www.mydomain.com/return.php');
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = urlVariables;
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
urlLoader.addEventListener(Event.COMPLETE, loadComplete);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, loadIOError);
urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, loadSecurityError);
function loadComplete(e:Event):void {
trace(e.target.data);
}
function loadIOError(event:IOErrorEvent):void {
trace("IOError: "+event);
}
function loadSecurityError(event:SecurityErrorEvent):void {
trace("SecurityError: "+event);
}
try {
urlLoader.load(urlRequest);
} catch (error:ArgumentError) {
trace("ArgumentError: "+error);
} catch (error:MemoryError) {
trace("MemoryError: "+error);
} catch (error:SecurityError) {
trace("SecurityError: "+error);
} catch (error:TypeError) {
trace("TypeError: "+error);
} catch (error:Error) {
trace("Unknown Error: "+error);
}
My PHP file looks like this:
<?PHP
$array = array();
foreach ($_POST as $key=>$value) {
array_push($array, $key.'='.urlencode($value));
}
$string = implode('&', $array);
echo $string;
?>
Any advice?
/ Frank