开发者

NSURLConnection cache clearing and reconnecting problem problem

Given a rails application which communicates with my ipad app. I'm 开发者_运维百科using async connection with http authentication. And i would like to test the credentials if they are ok. The problem is that if i enter the good credentials and after that i'm changing to a wrong one, the connection still accepts. Only refuses when I reopen the application. Might be some caching issue, i tried to clear the cache also on the ipad.

Connection initialization.

 NSURLRequest *request =
[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:3000"] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:60.0];
[NSURLConnection connectionWithRequest:request delegate:self];

also implemented the willcacheresponse method

- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse {
return nil;
}


Do you happen to cache the credential cache? If not, you can neglect all the following:)

I don't know which authentication mode you choose, here I have an sample using Windows authentication mode in my iphone app. When server side challenges client side, my app will send back a NSURLCredential object:

NSURLCredential* credential = [NSURLCredential credentialWithUser:login password:password persistence:NSURLCredentialPersistenceForSession];

Here you can see the parameter NSURLCredentialPersistenceForSession, following are the description:

typedef enum {
 NSURLCredentialPersistenceNone,       // Credential won't be stored.
 NSURLCredentialPersistenceForSession, // Credential will be stored only for this session.
 NSURLCredentialPersistencePermanent   // Credential will be stored in the user’s keychain and shared with other applications.
} NSURLCredentialPersistence;  

As you can see, if you use NSURLCredentialPersistenceForSession, the credential will be cached, and the callback connection: didReceiveAuthenticationChallenge: will never be called when server challenges client unless you clear it in NSURLCredentialStorage. So this makes your change of credential useless. You can use NSURLCredentialPersistenceNone to disable the cache or clear the cache when necessory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜