views:

136

answers:

1

I'm trying to send some XML to a rails app in Flex. I'm using the URLRequest and URLLoader objects. However, I'm having trouble determining how to send the XML and _method parameter to the rails app using these flash objects. Below is how I'm currently trying to achieve this.

        var request:URLRequest = new URLRequest();
        request.method = URLRequestMethod.POST;
        request.data = new Object();
        request.data.xml = Blog.xml.toXMLString();
        request.contentType = "text/xml";
        var loader:URLLoader = new URLLoader();
        loader.addEventListener(Event.COMPLETE, saveCompleteHandler);
        var saveUrl:String = "";
        saveUrl = BASE_URL;

        if (Blog.isNewBlog)
        {
            // Set the rails REST method.
            request.data._method = "POST";
            saveUrl += "blogs.xml";
        }
        else
        {
            // Set the rails REST method.
            request.data._method = "PUT";
            saveUrl += "blogs/" + Blog.id.toString() + ".xml";
        }
        request.url = saveUrl;
        //trace(request.data.toString());
        loader.load(request);

However the only data that is getting sent to the server is [Object object]. If some one could let me know where I'm going wrong I'd greatly appreciate it. Thanks.

+1  A: 

You probably want to use a URLVariables object for request.data.

var request:URLRequest = new URLRequest();
request.data = new URLVariables();
request.data.xml = Blog.xml.toXMLString();
...

When the data is serialized, I think it will be in the format you're expecting. I'm basing this off of the API description for URLRequest.data.

Kai