大家上午,NSURLConnection的,的NSURLRequest,不可信的證書和用戶身份驗證
我一直在嘗試寫做一些需要驗證遠程Web服務獲取的應用程序。我的主要問題是大多數這些遠程服務器(並且有很多)沒有有效的證書。我有code to accept the invalid certificate和代碼來回應正確的uname &通過挑戰(下)。我遇到的問題是讓兩人一起玩。我似乎無法找到一種方法來發送挑戰NSURLCredential
或一種正確鏈接回調的方法。當我嘗試鏈接他們時,我無法將我的NSURLRequest
撥打電話didReceiveAuthenticationChallenge
兩次。
任何想法,將不勝感激!
規範認證...
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if(!hasCanceled){
if ([challenge previousFailureCount] == 0) {
NSURLCredential *newCredential;
newCredential=[NSURLCredential credentialWithUser:_username password:_password persistence:NSURLCredentialPersistenceNone];
[[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
}
else {
[[challenge sender] cancelAuthenticationChallenge:challenge];
NSLog(@"Bad Username Or Password");
badUsernameAndPassword = YES;
finished = YES;
}
}
}
工作就像一個魅力。需要正確實施「canAuthenticateAgainstProtectionSpace」方法來讓我的應用程序調用此方法。但之後一切都很好。謝謝! – Staros 2010-06-03 20:44:51