开发者

Flash/Flex sending XML to Rails App

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 开发者_Go百科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.


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.


Old post, but may be useful: besides

request.data.xml = Blog.xml.toXMLString();

you can also do

request.data['xml'] = Blog.xml.toXMLString();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜