I want to check the last modified date on a file on a web server. Any help would be great. Thanks.
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:aURL];
NSHTTPURLResponse *response;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
if( [response respondsToSelector:@selector( allHeaderFields )] )
{
NSDictionary *metaData = [response allHeaderFields];
NSString *lastModifiedString = [metaData objectForKey:@"Last-Modified"];
}
This will first download the whole file from the server. I have modified the code myself in order to just get the header info. Here's the code
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:urlString cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0f];
[request setHTTPMethod:@"HEAD"];
NSHTTPURLResponse *response;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
if( [response respondsToSelector:@selector( allHeaderFields )] )
{
NSDictionary *metaData = [response allHeaderFields];
NSString *lastModifiedString = [metaData objectForKey:@"Last-Modified"];
NSLog(@"Date = %@",lastModifiedString);
}
[request release];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With