AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager setTaskDidReceiveAuthenticationChallengeBlock:^ NSURLSessionAuthChallengeDisposition(NSURLSession * _Nonnull session, NSURLSessionTask * _Nonnull task, NSURLAuthenticationChallenge * _Nonnull challenge, NSURLCredential *__autoreleasing _Nullable * _Nullable credential)
{
if (challenge.previousFailureCount == 0) {
NSURLCredential *myCredential = [[NSURLCredential alloc]initWithUser:用户名 password:密码 persistence:NSURLCredentialPersistenceForSession];
*credential = myCredential;
return NSURLSessionAuthChallengeUseCredential;
} else {
return NSURLSessionAuthChallengeCancelAuthenticationChallenge;
}
}];
id successBlock = ^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject){
// 请求成功
};
id failureBlock = ^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error){
// 请求失败
};
[manager GET:url parameters:params success:successBlock failure:failureBlock];
AFNetworking(AFHTTPSessionManager)之http摘要认证(DIGEST)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 一、什么是HTTP基本认证 客户端(桌面应用程序)通过HTTP协议跟Web服务器交互, 客户端一般不会使用cook...