XML sendAndLoad Location header issue?

Hi there. I seem to be in a bit of a bind. Anyone that can help me out gets major kudos :slight_smile: and mad ActionScript skills points (or something). My Flash skills are admittedly a little rusty, but bear with me…

So I have a RESTful resource that gets looked up from a flash widget client. If the resource is not found, the ActionScript will create the resource by posting to a URL like /articles.xml with the appropriate data. If this is successful, the backend returns a 201 status and sets the HTTP Location header with the address of the newly-created resource. My understanding was that ActionScript, upon seeing the location header set, would essentially grab the document at that URL like a redirect and make it available to me in the XML object. Here’s some code:

var create_params:String = "<article><foo>abc</foo><bar>xyz</bar></article>";
var create_xml:XML = new XML(create_params);
var reply_xml:XML = new XML();

reply_xml.ignoreWhite = true;
create_xml.ignoreWhite = true;
reply_xml.contentType = "application/xml";
create_xml.contentType = "application/xml";

reply_xml.onLoad = function(success) {
  if (success) {
    trace("[article] got reply. did we create the article?");
    trace("[article] " + this);
  } else {
    trace("[article] failed to contact server");
  }
}

create_xml.sendAndLoad(server_address, reply_xml);

The resource gets created as expected, which means the ‘send’ part works fine. And if I examine the results returned in a sniffer, or test using Curl, the Location header is indeed set by the server side. However, the Flash never makes a request to my server for the new resource and therefore when I examine the XML object, there isn’t any data there.

Is this not how sendAndLoad is supposed to react to the location header? I can’t seem to find any documentation on it or other people with similar issues, so I’m kind of puzzled. If it doesn’t auto-redirect to grab the new resource, is there a way I can pull the value of the location header into a variable so I can at least manually fetch it?

Another option of course is to change the backend code to return the newly created resource instead of a reference to it, but that doesn’t seem very RESTful to me and I’d rather avoid it. Even if I do go down that path, I’d really like an explanation for this behavior first…

Thanks much if you can help.

I’m using MX 2004 (yes, I know, out of date) and ActionScript 2.0.