【发布时间】:2011-02-26 08:06:12
【问题描述】:
大家早上好,
我一直在尝试编写一个应用程序,该应用程序从需要身份验证的远程 Web 服务执行一些 GET。我的主要问题是这些远程服务器中的大多数(并且有很多)没有有效的证书。我有code to accept the invalid certificate 和代码,可以用正确的 uname 和 pass 来响应挑战(如下)。我遇到的问题是让两个人一起玩。我似乎无法找到发送挑战的方法NSURLCredentials 或正确链接回调的方法。当我尝试链接它们时,我无法让我的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;
}
}
}
【问题讨论】:
标签: iphone cocoa nsurlconnection nsurlrequest nsurlcredential