Flash/Flex doesn’t support PUT or DELETE requests, because the browsers don’t β due to limitations in the NPAPI. This is a source of frustration. Workarounds using sockets or prioxies are messy, don’t work with binary data or some other problem…
But fortunately, there seems to be a good (enough) solution!
Keenan, at Automata Studios, blogs about using an extra request header parameter (X-HTTP-Method-Override), a method that seems to be accepted by Google among others. Good news!
To submit a DELETE request from flash, all I have to do is setting the requestHeaders X-HTTP-Method-Override parameter with the value “DELETE”:
var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, onComplete); var request:URLRequest = new URLRequest("http://url/to/rest/server"); request.method = URLRequestMethod.POST; request.data = "dummyData"; // Some data needed, otherwise sent as GET request! request.requestHeaders = [new URLRequestHeader("X-HTTP-Method-Override", "DELETE")]; loader.load(request);
Using php, this can be handled on the server side like this:
$method = (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) ? $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] : $_SERVER['REQUEST_METHOD']; echo $method;
if the server parameter for HTTP_X_HTTP_METHOD_OVERRIDE is set, it picks the request method from that parameter value, otherwise from the normal REQUEST_METHOD value.
Not a truly genuine RESTful solution, but close enough! π Thank you, Keenan!
Daniel
September 9, 2011
I am having difficult to implement delete method with HTTPService in Flex. I read your example , and liked. I think this can be a sollution.
The result of my request need to be an XML file. In your post, you donΒ΄t put the onComplete method. You can send me an email ?
Thanks