views:

51

answers:

2

I'm trying to streamline my error reporting for internal testing. When I use URLLoader/URLRequest to load a page that responds with the 500 HTTP status code, I catch it with the IOErrorEvent.IO_ERROR, but can't find a way to get the response body. Unlike with Event.Complete, loader.data (My URLLoader) is an empty string.

Yes, I can use Fiddler/Firebug to get the actual response, but this would be good to catch intermittent/hard-to-reproduce errors when I don't have these running.

+1  A: 

Try adding an event listener to your URLLoader for flash.events.HTTPStatusEvent.HTTP_STATUS. That will definitely get you the code, though as for the body...AIR exposes flash.events.HTTPStatusEvent.HTTP_RESPONSE_STATUS which will get you headers and such, though I don't think that is going to help you here.

Tegeril
A: 

Its been some time since I fiddled with this in Flash. But I recently had the same problem in Silverlight, and the problem turned out to be the at the browser would process the responce first, so I could only get the browser "user friendly" error page. I Silverlight you can get around this by using the ClientHTTP network stack. Which makes the webrequest directly through the OS instead of through the browsers network stack.

I am almost 100% sure there is no such thing in Flash, which leads me to believe you cannot get the body for any other status code than 200. So you are proberly stuck. One solution is to have an optional parameter on your webservice, that when set, will cause all methods to return 200 and just write out any exceptions thrown.

Lillemanden
This might explain why HTTPStatusEvent.HTTP_RESPONSE_STATUS is only available for Adobe AIR.
Tegeril