Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
700 views
in Technique[技术] by (71.8m points)

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

I have this flash code. It sends score and username in my game to savescores.php. But I have the error above. I have changed URLLoaderDataForma.VARIABLES to TEXT but still same error occurs. What should i do to fix this problem? Thanks in advance..

private function SendScore(score:int) 
    {
        var variables:URLVariables = new URLVariables();
        variables.score = score;
        variables.username = username;
        var urlloader:URLLoader = new URLLoader();

        var urlrequest:URLRequest = new URLRequest('http://localhost:90/savescores.php');
        urlrequest.method = URLRequestMethod.POST;
        urlrequest.data = variables;
        urlloader.dataFormat = URLLoaderDataFormat.TEXT;

        urlloader.load(urlrequest);
        urlloader.addEventListener(Event.COMPLETE, CompleteHandler, false, 0, true);
        urlloader.addEventListener(IOErrorEvent.IO_ERROR , ErrorHandler, false, 0, true);
    }

    private function CompleteHandler(e:Event) 
    {
        var vars:URLVariables = new URLVariables(e.target.data);
        if(vars.success) trace('Saving succeeded');
        else ('Saving failed');
    }

    private function ErrorHandler(e:IOErrorEvent) 
    {
        trace('Error occured');
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

ANSWER: Issue was with PHP

-- You must return a var to AS3 or you will get this error.

I am posting this because unless the viewer reads the comments they will not know what the issue was and a solution. Anil, who asked this question stated it was an issue with the PHP and not as3 but gave no reason as to why. It seems the answer marked correct above is not a sufficient answer because it only suggests a possible solution. Where Anil, admitted it was an issue with the php. I believe this answer is more complete and can help someone who has this same issue.

I had a similar issue. The problem was with the php. Unless you output something back from the php you will get this error.

Flash did not like nothing being returned from php and gave the following error:

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 was a part of my PHP that did not return anything:

if($ConfirmedEmail=="true")
{
    echo "Status=true";
}
if($ConfirmedEmail=="false")
{
    echo "Status=false";
}

But if it was neither true/false it would OUTPUT NOTHING. = Flash Does Not Like!

So the PHP code had to be this:

if($ConfirmedEmail=="true")
{
    echo "Status=true";
}
else if($ConfirmedEmail=="false")
{
    echo "Status=false";
}
else
{
    echo "Status=Nada";
}

Here is my AS3 code for you to look at. Hope it helps someone.

public function checkEmail(e:Event = null)
{

    var urlreq = new URLRequest("http://www.MyWebsite.com/myScript.php");
    urlreq.method = URLRequestMethod.POST;

    var urlvars = new URLVariables();
    urlvars.userID = Main.userID;


    urlreq.data = urlvars;

    var loader:URLLoader = new URLLoader(urlreq);
    loader.addEventListener(Event.COMPLETE, completed);
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.load(urlreq);
}

public function completed(event:Event):void
{
    var variables:URLVariables = new URLVariables(event.target.data);
    trace("Email Confirmed: " + variables.Status);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...