开发者

Flash/Flex sending XML to Rails App

开发者 https://www.devze.com 2022-12-25 19:49 出处:网络
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 ap

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

精彩评论

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