In a joint project there is a Flash application that uses some kind of API (an incomplete process, a bundle of a related PHP method). The API used to serve data in JSON, but now we need support for a different format. There are several ways to specify the format in which we expect data to be returned. I would like to take part in the HTTP Accept header to avoid re-creating the wheel.
In our Flash application, we have a standard code group responsible for setting the Accept header.
var request:URLRequest = new URLRequest(url); var acceptHeader:URLRequestHeader = new URLRequestHeader("Accept", "application/json"); request.requestHeaders.push(acceptHeader); request.method = URLRequestMethod.POST;
This works fine in Internet Explorer and Chrome / Chromium - web consoles show that the title has changed as expected (bottom of them). But Firefox / Iceweasel is showing strange behavior. According to the header section of the built-in inspector, the standard header is only transmitted:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Running Live HTTP headers (FF extension) and catching requests from the application leads to the appearance of other people's results (unimportant headers are omitted, path changes, etc.):
POST /path-to-script.phtml?id=1 HTTP/1.1 Host: devserver.com Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 <...> Referer: http://devserver.com/path-to-flash.swf Content-Type: application/x-www-form-urlencoded Accept: application/json <POST payload>
The actual payload is a stub because URLRequest prevents the headers from being changed for the GET method. For some reason, the payload and the last three headers are also indented, making them part of the request body rather than request headers.
Skimming through POST requests in Firefox - actually in Iceweasel 9.01 on Debian, if that matters, the same thing happens in FF10 on Win7 - shows other cases with the same symptoms. Namely, on community.adobe.com , but requests from SWF are accompanied by both the Accept header and the POST parameter indicating the desired JSON format.
So there are two questions:
Is it possible to overwrite the default HTTP header from SWF opened through Firefox? Are we something wrong?
Is it better to repeat the use of this HTTP tool, or perhaps we need to stick with an additional parameter and start rewriting URLs to things like /api/someObject.<json|xml>/123 ?