2010-02-22 95 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]。嘗試打印其描述以確保它不爲零。

相關問題