Search code examples
flashapache-flexpostairsakai

Do POST in AIR application


I'm trying to post data to a page that handles it for me. I always get following error, however:

ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://localhost:8080/_user/a/ad/admin/message.create.html" errorID=2032] Blockquote

This is the code I have so far. This works fine for GET requests.

        // Object that contains data of the message to be sent
        var toSend:Object = {
            "sakai:type": "internal",
            "sakai:sendstate": "pending",
            "sakai:messagebox": "outbox",
            "sakai:to": "internal:"+sakaimain.gui.dgMessages.selectedItem["to"],
            "sakai:subject": sakaimain.gui.dgMessages.selectedItem["subject"],
            "sakai:body":"testreply with AIR GUI",
            "sakai:previousmessage" : sakaimain.gui.dgMessages.selectedItem["id"]
        };
        // Send message
        // Create loader to load objects
        var loader:URLLoader = new URLLoader();
        // Add event listeners for error and complete events
        loader.addEventListener(Event.COMPLETE, replyMessageCompleteHandler);
        loader.addEventListener(IOErrorEvent.IO_ERROR, replyMessageErrorHandler);
        // Create the request to be done
        var request:URLRequest = new URLRequest("http://localhost:8080/_user/a/ad/admin/message.create.html");
        request.requestHeaders = new Array(new URLRequestHeader("x-sakai-token", sakaimain.token ));
        request.method = URLRequestMethod.POST;
        request.data = toSend;
        // Do the request
        loader.load(request);

Anyone seeing the problem here?


Solution

  • The problem has been solved. I created URLVariables instead of an object to pass through which fixed the problem.

    var urlv:URLVariables = new URLVariables();
    urlv["sakai:type"] = "internal";
    urlv["sakai:sendstate"] = "pending";
    urlv["sakai:messagebox"] = "outbox";
    urlv["sakai:to"] = "internal:"+sakaimain.gui.dgMessages.selectedItem["from"];
    urlv["sakai:subject"] = sakaimain.gui.dgMessages.selectedItem["subject"];
    urlv["sakai:body"] ="testreply with AIR GUI";
    urlv["sakai:previousmessage" ] = sakaimain.gui.dgMessages.selectedItem["id"];