有人知道如何在 2.0 版本的 AFNetworking 中处理身份验证吗?我尝试了以下但没有成功。该块被调用(我在那里有一个 NSLog)但响应仍然是 401 错误
[self setTaskDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition(NSURLSession *session, NSURLSessionTask *task, NSURLAuthenticationChallenge *challenge, NSURLCredential *__autoreleasing *credential) {
*credential = [[NSURLCredential alloc] initWithUser:username password:password persistence:NSURLCredentialPersistenceForSession];
return NSURLSessionAuthChallengeUseCredential;
}];