DidReceiveAuthenticationChallenge receives a call only once iPhone

I connect to the server using NSURLConnection . The server asks for basic authentication, for which I use delegate methods: - didReceiveAuthenticationChallenge . But this is called only once. If I change the password to some other value, then the delegate methods will not be called and my login will be successful?

Any help would be appreciated.

Thanks.

+3
source share
4 answers

Solved!

It turns out that NSURLConnection behaved correctly, i.e. didReceiveAuthenticationChallenge: called for each authentication.

The problem was that the server did not send calls after the first. This turned out because the server set the cookie.

You can force a new call to simply delete the cookie. Since there are no other useful files for this server, I will simply delete them all:

 - (void)clearCookiesForURL { NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; NSArray *cookies = [cookieStorage cookiesForURL:_URL]; for (NSHTTPCookie *cookie in cookies) { NSLog(@"Deleting cookie for domain: %@", [cookie domain]); [cookieStorage deleteCookie:cookie]; } } 
+6
source

You need to follow these steps to close the session completely.

  • Delete all cookies
  • Delete all credentials
  • NSURLCredentialPersistenceNone
+1
source

Unfortunately, there is currently no easy way to accomplish what you requested:

Apple informative explanation: TLS Session Cache

Open Radar Error Request: Unable to flush TLS cache with NSURLConnection

+1
source

NSURLConnection will cache credentials. The following is an approach to finding and erasing certain credentials (so you are again questioned):

Is it possible to prevent NSURLRequest from trying to cache data or delete cached data after a request?

Hope this works for you, Steve

0
source

All Articles