I'm using URLLoader to POST to a server. The xml response from the server can respond with a 404 or a 403 (forbidden) error. However I am unable to get the response codes.
Here is the code
var urlString:String = "some url";
var urlRequest:URLRequest = new URLRequest(urlString);
var loader:URLLoader = new URLLoader();
loader.addEventListener( Event.COMPLETE, setXMLData );
loader.addEventListener( IOErrorEvent.IO_ERROR, ioHandler );
loader.addEventListener( HTTPStatusEvent.HTTP_STATUS, httpStatusHandler );
//...
public function httpStatusHandler(evt:HTTPStatusEvent):void {
trace("status is " + evt.status);
}
status is always 0 regardless whether i return 200, 400, 404, 301, 500, etc...
Any ideas?
For AIR Only you can use the httpResponseStatus. Otherwise in Flash/Flex without AIR you cannot.
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLLoader.html#event:httpResponseStatus
httpResponseStatus Event
Event Object Type: flash.events.HTTPStatusEvent
HTTPStatusEvent.type property = flash.events.HTTPStatusEvent.HTTP_RESPONSE_STATUS
Language Version : ActionScript 3.0
Runtime Versions : AIR 1.0 AIR 1.0
Dispatched if a call to the load() method attempts to access data over HTTP, and Adobe AIR is able to detect and return the status code for the request.
Unlike the httpStatus event, the httpResponseStatus event is delivered before any response data. Also, the httpResponseStatus event includes values for the responseHeaders and responseURL properties (which are undefined for an httpStatus event. Note that the httpResponseStatus event (if any) will be sent before (and in addition to) any complete or error event.
the ability to look at the headers is limited in several browsers, therefore flash has a problem with being passed the information. this is mainly blamed on the browser settings, but i have yet to find one where it actually works. status event output.
i gave up and had the file print the response code in my projects, not wonderful (and somewhat defeating the point) but seems to work.
As a late answer (FWIW):
From what I've read, the status codes you get depend on what browser the Flash player is running in.
One article says you can only get 200 or 500. One SO question says they were getting 207 in Chrome but 0 in Firefox.
I, personally, have tested using the dev Flash player as well as an ActiveX version and was able to get many different 2XX/4XX HTTP status codes (but couldn't get the 3XX redirect codes I tried because the requests got redirected and returned 200s).