Does anyone know how to send If Modified Since header with a url request?
I'm trying to get a status code back that will tell me if an RSS page has been updated or not.
UPDATE #1: I was able to do a test doing the following:
NSURL *url = [NSURL URLWithString:self.url];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request addValue:@"Tue, 18 Nov 2014 20:46:46 GMT" forHTTPHeaderField:@"If-Modified-Since"];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
int responseCode = (int)[httpResponse statusCode];
NSLog(@"All headers: %@", [httpResponse allHeaderFields]);
NSLog(@"Status code:: %d", responseCode);
}];
What's weird though, if I delete my entire iOS application and run it I get the 304 status code. But, if I comment out the line where I add the If-Modified-Since value and re-run it -- then I get the 200 but when I uncomment that line and re-run it -- then the 304 error doesn't come back... It's a 200 error code. The only way to get the 304 error back is by deleting the entire application off my iPhone device.
Any ideas what's going on?
A little late with this but since NSURLConnection is caching the responses in order to get the 304 code you should create your request like this.