Reputation: 1034
I'm using NSURLSession dataTaskWithRequest:completionHandler:
to make some requests to my server. I'm using a self-signed certificate, so when the delegate's URLSession:didReceiveChallenge:completionHandler:
gets called, I can do my internal checks to verify it everything is fine.
This all works great on the first request I send. After I call the completion handler with NSURLSessionAuthChallengeUseCredential
, then the next requests never call URLSession:didReceiveChallenge:completionHandler:
.
For reasons I won't go into in this post, I would really like URLSession:didReceiveChallenge:completionHandler:
to be called each time, so that I can do my own checking. I'm assuming NSURLSession is somehow caching the certificate and keeping it in some sort of "valid certificates" list so it's not doing this check each time. I want to clear this cache so that I can make my own check each time. If I restart the App, then URLSession:didReceiveChallenge:completionHandler:
does get called once more.
I have tried setting the Credential Storage to nil with no success:
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration.URLCredentialStorage = nil;
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
[[session dataTaskWithRequest:request
completionHandler:^(NSData *data,
NSURLResponse *response,
NSError *error) {
...
}] resume];
Any ideas how to accomplish this?
Thank you!
Upvotes: 4
Views: 2362
Reputation: 16649
For someone who tried everything here can be problem in the backend. So this problem was fixed by disabling ssl session caching in nginx server.
Upvotes: 0