HI,
I'm trying to get files recently modified on a server. I use for that the If-Modified-Since HTTP header, and the server send correct respons with 304 (not modified) status.
On the iOS device, I get no error and empty data.
Here is the method I use:
- (void)getContentOfURL:(NSString*)url ifModifiedSince:(NSString*)sinceDate completionBlock:(DataWebServiceCompletionBlock)completionBlock {
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData // NSURLRequestReloadIgnoringLocalCacheData / NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod: @"GET"];
[request setValue:sinceDate forHTTPHeaderField:@"If-Modified-Since"]; // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
NSURLSessionDataTask * task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (completionBlock) {
completionBlock(data, error); // the server send 304 status, but I get error == nil and data.lenght = 0
}
});
}];
[task resume];
}
Any idea ?