从Flash AS3发送Json表单

meg*_*ana 2 flash json form-post actionscript-3

我有一个表格接受Asp.net中的json帖子,我需要从Flash As3调用...

我正在使用下面的代码来做到这一点.我看过一些他们说工作正常的帖子.但我遇到下面的错误

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

这是我的代码.

        var messages:Array = new Array ();


        messages.push({"From":fromemailTxt.text,"To": ToemailTxt.text,"Body": BodyText.text,"Subject":SubjectText.text});

        var JsonObj:String = JSON.encode(messages);
        trace(JsonObj);

        var variables:URLVariables=new URLVariables(JsonObj);



        RequestURL= srvStringURL;

        var JSONLoader:URLLoader = new URLLoader();
        JSONLoader.dataFormat=URLLoaderDataFormat.TEXT;

        JSONLoader.addEventListener(IOErrorEvent.IO_ERROR, GetBookmarkURLError, false, 0, true);
        JSONLoader.addEventListener(Event.COMPLETE, parseBookmarkURLResult, false, 0, true);


        var hdr:URLRequestHeader = new URLRequestHeader("Content-type", "application/json");

        var request:URLRequest = new URLRequest(RequestURL);
        request.requestHeaders.push(hdr);
        request.data=variables;
        request.method = URLRequestMethod.POST;

        try 
        {
            JSONLoader.load(request);
        }
        catch (error:ArgumentError) 
        { 
            trace("An ArgumentError has occurred."+error.errorID.toString()); 
        } 
        catch (error:SecurityError) 
        { 
            trace("A SecurityError has occurred."); 
        }
        catch (error:Error) 
        {
            trace("Unable to load requested document.");
        }
Run Code Online (Sandbox Code Playgroud)

有谁对此有任何想法?谢谢

Eng*_*eer 7

错误是,因为您将错误的字符串传递给URLVariables构造函数.不要使用URLVariables.而是将数据传递为字符串:request.data=JsonObj;