0
我需要使用摘要身份驗證,但AFNetworking它不工作摘要訪問身份驗證AFNetworking
我需要使用摘要身份驗證,但AFNetworking它不工作摘要訪問身份驗證AFNetworking
這裏什麼工作對我來說
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSURLCredential *credential = [[NSURLCredential alloc] initWithUser:@"Username" password:@"Password" persistence:NSURLCredentialPersistenceForSession];
[manager setCredential:credential];
要使用AFNetworking 3.0工作,可以使用下面的代碼爲AFURLSessionManager。
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
[manager setTaskDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition(NSURLSession * _Nonnull session, NSURLSessionTask * _Nonnull task, NSURLAuthenticationChallenge * _Nonnull challenge, NSURLCredential *__autoreleasing _Nullable * _Nullable credential) {
NSString *authenicationMethod = challenge.protectionSpace.authenticationMethod;
NSLog(@"Receive challenge: %@", authenicationMethod);
if ([authenicationMethod isEqualToString:NSURLAuthenticationMethodHTTPDigest]) {
*credential = [NSURLCredential credentialWithUser:@"username" password:@"password" persistence:NSURLCredentialPersistenceForSession];
return NSURLSessionAuthChallengeUseCredential;
}
return NSURLSessionAuthChallengeCancelAuthenticationChallenge;
}];
這不再適用於AFNetworking 3 – itinance