Question

i am having one form accepting json post in Asp.net which i need to call from Flash As3...

i am using below code to do that. I have seen some post in which they say its working fine. But i am encountering below Error

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

Here is my code.

        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.");
        }

Anybody have any idea on this?? Thanks

Was it helpful?

Solution

The error is, because you are passing incorrect string to URLVariables constructor. Do not use URLVariables. Instead pass data as string: request.data=JsonObj;

OTHER TIPS

Below is the code I am using to consume REST Web service and pass json parameter to service it shows. Error #2032: Stream Error. Andy idea what is going wrong

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

var strData:String = "{\"gparam\": [ {\"productid\": \"" + productId + "\"},{\"message\": \"" + mesage + "\"},{\"googleappid\": \"" + googleappid + "\"},{\"senderid\": \"" + senderid + "\"},{\"appname\": \"" + appName + "\"},{\"userid\": \"" + userId + "\"},{\"receiverid\": \"" + receiverId + "\"} ]}";

var hdr:URLRequestHeader = new URLRequestHeader("Content-type", "application/json");
var req:URLRequest = new URLRequest("http://localhost/AndroidGCM/GCMNotification.svc/SendGCM");
req.requestHeaders.push(hdr);
req.method = URLRequestMethod.POST;
req.data = strData;

trace("data: " + req.data);

ldr.addEventListener(Event.COMPLETE,onComplete);
ldr.addEventListener(IOErrorEvent.IO_ERROR , onError);
ldr.addEventListener(SecurityErrorEvent.SECURITY_ERROR ,onSecurityErr);

ldr.load(req);

function onComplete(e:Event):void
{
    trace("LOAD COMPLETE: " + ldr.data);
TextField(parMC.getChildByName("txtCheck")).appendText("\n LOAD COMPLETE: " + ldr.data);
}
function onSecurityErr(e:SecurityErrorEvent):void
{
    trace("error: " + e.text );
}
function onError(e:IOErrorEvent):void
{
    trace("error: " + e.toString());
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top