2010-02-22 68 views
2

如果网站不需要验证,我的代码就可以正常工作,如果是这样,那么在打印“凭证已创建”之后,EXC_BAD_ACCESS会出错。我没有发布任何东西,这个代码直接从文档中复制 - 任何想法有什么不对?didReceiveAuthenticationChallenge导致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]; 
} 
} 

回答

1

原来,这是与该特定的网站身份验证方法有关 - 替换我想登录到另一个网站的网站和代码工作正常。

(我试图从unRaid的状态页面抽取数据,unRaid不使用实际的Web服务器,但emhttp所以我假设有什么用它做)

0

您唯一不能控制的是返回值[challenge sender]。尝试打印其描述以确保它不为零。