Pergunta

Se o site não exigir autenticação, meu código funcionará bem, se funcionar, erra com EXC_BAD_ACCESS logo após a impressão de "Credencial Created". Não estou lançando nada, e esse código é copiado diretamente da documentação - alguma idéia do que há de errado?

- (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];
 }
}
Foi útil?

Solução

Acontece que tem algo a ver com esse método de autenticação de sites específicos - substituindo o site que quero fazer login com outro site e o código funciona bem.

(Eu estava tentando raspar os dados da página de status da Unraid, não -Adida, não usa um servidor da web, mas emhttp, então estou assumindo que isso tem algo a ver com isso)

Outras dicas

A única coisa que você não está controlando é o valor de retorno de [challenge sender]. Tente imprimir sua descrição para garantir que não seja nil.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top