始终在NSURLSessionDataTask中获取缓存数据

gpi*_*ler 5 json nsurlconnection ios nsurlsession

在使用NSURLSessionDataTask向服务器发布JSON请求时,我遇到了一个非常奇怪的问题.

第一个请求通过,我收到正确的JSON响应,当我做第二个请求时,我总是返回旧的响应,服务器永远不会收到请求.即使我打开飞机模式NSURLSessionDataTask也能正常工作,我再次回复旧的响应.

那是我正在使用的代码:

- (void)getJSONFromURL:(NSURL*)url identifierCode:(NSInteger)code
{
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request addValue:[DataController sharedInstance].currentUser.userToken forHTTPHeaderField:@"User-Token"];
[request setHTTPMethod:@"GET"];

if (![SVProgressHUD isVisible])
    [SVProgressHUD show];

NSURLSessionDataTask *postTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error){
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

    [self handleResponse:httpResponse withJSON:json identifierCode:code];

    dispatch_async(dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
    });
}];

[postTask resume];
Run Code Online (Sandbox Code Playgroud)

}

gpi*_*ler 8

我发现了这个问题,我不知道为什么会发生这种变化,因为我以前从未设置过该属性.无论如何,我设置configuration.URLCache = NULL;,现在everthing再次正常工作.