didReceiveAuthenticationChallenge造成EXC_BAD_ACCESS
-
22-09-2019 - |
题
如果网站不需要身份验证,我的代码工作正常,如果是这样,它的错误与EXC_BAD_ACCESS打印“证书创建”之后。我没有任何释放,而这种代码是从文件复制直 - 任何想法有什么错
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge previousFailureCount] == 0)
{
NSLog(@"received authentication challenge");
NSURLCredential *newCredential;
newCredential=[NSURLCredential credentialWithUser:@"root"
password:@"rootpassword"
persistence:NSURLCredentialPersistenceForSession];
NSLog(@"credential created");
[[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
NSLog(@"responded to authentication challenge");
}
else
{
NSLog(@"previous authentication failure");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Authentication Failure"
message:@"Website did not accept the username and password."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
解决方案
原来它的是与该特定网站的身份验证方法 - 更换网站,我想登录到另一个网站和代码工作正常
(我是从unRaid的状态页面试图抽取数据,unRaid不使用实际的Web服务器,但emhttp所以我假设有什么关系呢)
其他提示
你不控制的唯一的事情是[challenge sender]
的返回值。尝试打印它的描述,以确保它的非空。
不隶属于 StackOverflow