diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index fa4b488..8c4edf2 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -550,13 +550,13 @@ didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge if ([challenge previousFailureCount] == 0) { NSURLCredential *credential = nil; - NSString *username = [[self.request URL] user]; + NSString *user = [[self.request URL] user]; NSString *password = [[self.request URL] password]; - if (username && password) { - credential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceNone]; - } else if (username) { - credential = [[[NSURLCredentialStorage sharedCredentialStorage] credentialsForProtectionSpace:[challenge protectionSpace]] objectForKey:username]; + if (user && password) { + credential = [NSURLCredential credentialWithUser:user password:password persistence:NSURLCredentialPersistenceNone]; + } else if (user) { + credential = [[[NSURLCredentialStorage sharedCredentialStorage] credentialsForProtectionSpace:[challenge protectionSpace]] objectForKey:user]; } else { credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:[challenge protectionSpace]]; }