Using setRequestHeader with

You must Login before you can answer or comment on any questions.

I cant use setRequestHeader with "If-Modified-Since" to get back at 304 Status.

I want to use this for storing images and xml files on the device.

And everytime the xml or the image is requested by the application it should check if a newer version is found on the server.

Im sending the date "Mon, 19 Jul 2010 11:20:22 GMT"

And im receiving the date "Mon, 19 Jul 2010 10:20:17 GMT" from the server.

Usually it should work and return a 304 status.

if (Titanium.Network.online)
{
      var c = Titanium.Network.createHTTPClient();
      if (c.status == 304)
      {
        // XML File not necessary - Clientlog File is newer
        console.log('Use Client XML File - is newer than the server XML');
        fn_end(file_obj);
        return;
      }
      // ...here will follow some code to store the files on the device
 
      c.open('GET', url);
      c.setRequestHeader("If-Modified-Since", "Mon, 19 Jul 2010 11:20:22 GMT");
      c.send();
}

1 Answer

This works for me, nice and simple:

var url = <url to file on server>;
var xhr = Titanium.Network.createHTTPClient();
xhr.open('HEAD', url);
xhr.onload = function() {
    var fileModifiedDate =  new Date(xhr.getResponseHeader("Last-Modified"));
    .
    .
    .
};
xhr.send()

Your Answer

Think you can help? Login to answer this question!