views:

70

answers:

1

Hello,

I have an URL loader with the following code:

public function getUploadURL():void {   
    var request:URLRequest = new URLRequest();

    var url:String = getPath();
    // Adds time to prevent caching
    url += "&time=" + new Date().getTime(); 

    request.url = url;
    request.method = URLRequestMethod.GET;

    _loader = new URLLoader();
    _loader.dataFormat = URLLoaderDataFormat.TEXT;
    _loader.addEventListener(Event.COMPLETE, getBaseURL);
    _loader.addEventListener(IOErrorEvent.IO_ERROR, onGetUploadURLError);
    _loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, getHttpStatus);

    _loader.load(request);
}

My problem is that this request might be wrong, and so the server will give me a back a 400 Bad Request, with a message to explain the error. If the Event.COMPLETE, I can see some message (a response) back from the server in the "data" field of the Event, but if onGetUploadURLError or getHttpStatus is called, it just says that the error code is 400 but does not show me the message associated with it.

The "data" field is undefined in getHttpStatus and it is "" in onGetUploadURLError. On the contrary, in getBaseURL, I get: {"ResponseMetadata":{...}} I checked and I do get a similar response in my browser for a wrong request, but I cannot see it.

Any idea how I can please get the message?

Thank you very much, Rudy

+1  A: 

Flash does not handle HTTP status codes very well. Here is a blog post with comments from an Adobe employee saying the problem is actually the plug-in limitations. The Adobe employee points to a library for doing HTTP requests using AS3 through sockets but I doubt that would be highly efficient (compared to having the plugin-in hand requests off to the browser).

Standard practice on all projects I have ever worked on was to always send a 200 OK and add a error key onto the message.

edit: also see this bug which is exactly your issue.

James Fassett
Thank you, you gave me a great answer, I appreciate it a lot. Thanks!
Rudy
I am using the GET from the lib httpClient that you linked me too (as3httpclientlib). For what I am doing, it doesn't have to be that efficient so it works like a charm. Thanks for your help!
Rudy