我正在尝试在使用 AFNetworking 发送的 GET 请求中实现 etag 缓存,但我似乎无法找到具有 AFNetworking REST API ~AND~ 缓存的解决方案。需要显示如何发送 GET/POST 和控制缓存的示例代码。我现在拥有的只是请求,而不是缓存:
NSString *path = @"path/to/my.json";
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:self.baseNSURL];
[client registerHTTPOperationClass:[AFJSONRequestOperation class]];
[client setDefaultHeader:@"Accept" value:@"application/json"];
[client getPath:path
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@",responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@",error);
}
];
和传出的 HEADER (无缓存控制):
GET path/to/my.json HTTP/1.1 Host: xycom:80 Accept-Encoding: gzip, deflate Accept: application/json Cookie: PHPSESSID=35gojgf7s35n8fljlvd5pjudfn0 Connection: keep-alive Accept-Language: en, fr, de, ja, nl, it, es, pt, pt-PT, da, fi, nb, sv, ko, zh-Hans, zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi, en-us;q=0.8 User-Agent: myApp/1.0 (iPhone Simulator; iOS 6.1; Scale/1.00) X-Forwarded-For: 192.130 .1.00