Reading server error messages for a URLLoader

Posted by Rudy on Stack Overflow See other posts from Stack Overflow or by Rudy
Published on 2010-06-09T20:55:29Z Indexed on 2010/06/09 21:22 UTC
Read the original article Hit count: 281

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about urlloader