我将使用NSURLCredentialPersistencePermanent创建一个NSURLCredential,并使用它对AFHTTPRequestOperation进行身份验证,如下所示:
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSURLCredential *credential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistencePermanent];
[operation setCredential:credential];一旦通过身份验证,就不再需要在以后的操作中设置凭据。
但是,一旦我重新启动应用程序,而凭据仍然存在于[NSURLCredentialStorage sharedCredentialStorage]中,下一个AFHTTPRequestOperation将不再进行身份验证,并返回拒绝访问的响应。
为什么AFNetworking无法识别存在于共享凭据存储中的凭据?
发布于 2014-01-28 04:08:38
AFURLConnectionOperation (AFHTTPRequestOperation的超类)的shouldUseCredentialStorage属性在文档中默认是"YES .“。创建新操作时,AFHTTPRequestOperationManager会用其自己的shouldUseCredentialStorage值覆盖此值。
由于AFHTTPRequestOperationManager中的错误,shouldUseCredentialStorage永远不会初始化为YES (尽管文档中记录了它的默认值)。
解决方案(目前)是手动将请求或操作管理器的shouldUseCredentialStorage属性设置为YES。
https://stackoverflow.com/questions/21343886
复制相似问题