views:

490

answers:

2

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 );[/code]


  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?

A: 

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.

Todd Moses
yeah i have came to the conclusion that they didn't support it as well. thanks guys!
A: 

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.

shortstick