代码之家  ›  专栏  ›  技术社区  ›  BarrettJ

didReceiveAuthenticationChallenge导致EXC\u访问错误

  •  2
  • BarrettJ  · 技术社区  · 16 年前

    如果网站不需要身份验证,我的代码可以正常工作,如果需要,则在打印“credential created”后会出现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];
     }
    }
    
    2 回复  |  直到 16 年前
        1
  •  1
  •   BarrettJ    16 年前

    事实证明,这与特定的网站身份验证方法有关——用另一个网站替换我想登录的网站,代码工作正常。

    (我试图从unRaid的状态页中获取数据,unRaid不使用实际的Web服务器,而是使用emhttp,所以我假设这与此有关)

        2
  •  0
  •   Jeff Kelley    16 年前

    [challenge sender] . 请尝试打印它的描述,以确保它不是零。