I am trying to do a request on a server, which responds with an Etag for cache purposes. I have written the following code for it, but the response for these calls is random most of the time i.e. sometimes response status code is 200 and some times 304(expected). Am I doing something wrong in my code or is there something specific with AFNetworking that I should keep in mind.!
NSURL *url = [NSURL URLWithString:@"http://ia.media-imdb.com/images/M/MV5BNzI0NTY5NzQwMV5BMl5BanBnXkFtZTcwOTQyNTA5OA@@._V1._SY90_.jpg"];
NSMutableURLRequest *aRequest = [NSMutableURLRequest requestWithURL:url];
[aRequest setValue:@"\"61-smtLpBSL_SY90_#1\"" forHTTPHeaderField:@"If-None-Match"];
NSLog(@"headers: %@", aRequest.allHTTPHeaderFields);
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:aRequest imageProcessingBlock:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
NSLog(@"%@ %d", response.allHeaderFields, response.statusCode);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"Request failed with error: %@", error);
}];
[operation start];
I had the same problem, I managed to fix this by changing my request to
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:60];
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