我正在尝试在服务器上发出请求,该服务器使用 Etag 进行响应以用于缓存目的。我为它编写了以下代码,但这些调用的响应大部分时间是随机的,即有时响应状态代码是 200,有时是 304(预期)。我在我的代码中做错了什么,或者我应该记住 AFNetworking 的某些特定内容。!
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];