Skip to main content
January 4, 2012
Answered

HEAD request to detect updating of files at server

  • January 4, 2012
  • 1 reply
  • 577 views

Hi,

I'm trying to send a HEAD request from my AIR for Android Application.

Because, i want download the file only when it has been updated.

I have tried it with URLLoader and HTTPStatusEvent, but the length of reponseHeaders  is 0.

public function dwnLoadIconWheel():void

{

    var urlPub:String = _serverPath + datePath;

    //var urlRequest:URLRequestHeader

    //httpResponseStatus

    var loader:URLLoader = new URLLoader();

    loader.addEventListener(Event.COMPLETE, onPubWheelIconHandler);

    loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorPubWheelIconHandler);

    loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusPubWheelIconHandler);

    loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorPubWheelIconHandler);

    var header:URLRequestHeader = new URLRequestHeader("Created", "2008-06-04T22:45:25Z");

    var request:URLRequest = new URLRequest(_xmlServerEpaperUrl + globalPath);

    trace(request.url);

    request.method = URLRequestMethod.HEAD;

    request.requestHeaders.push(header);

    try {

        loader.load(request);

    } catch (error:Error) {

        trace("Unable to load requested document.");

    }

}

protected function httpStatusPubWheelIconHandler(event:HTTPStatusEvent):void

{

    var loader:URLLoader = URLLoader(event.target);

    loader.removeEventListener(Event.COMPLETE, onPubWheelIconHandler);

    loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorPubWheelIconHandler);

    loader.removeEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusPubWheelIconHandler);

    loader.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorPubWheelIconHandler);

    if (event.responseHeaders.length == 0)

        trace("Header length 0");

    else

        trace("Header received");

}

My questions is, if can i get the date of my file from server without download the complete file. Can i do HEAD requests to detect update of files?

Thanks!

This topic has been closed for replies.
Correct answer

I found the solution of the problem

The problem was that i had not used the event correct. I should have used a event of type HTTPStatusEvent.HTTP_RESPONSE_STATUS.

loader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, httpStatusPubWheelIconHandler);

1 reply

Correct answer
January 5, 2012

I found the solution of the problem

The problem was that i had not used the event correct. I should have used a event of type HTTPStatusEvent.HTTP_RESPONSE_STATUS.

loader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, httpStatusPubWheelIconHandler);