4
我在iOS编程中遇到了一些认证问题。我有一个在Windows 2003上完全针对IIS6的代码,但在Windows Server 2008上无法使用IIS7。两台服务器上的安全选项相同(不提供匿名访问和“集成Windows身份验证”)。针对IIS7和Windows 2008的iOS“didReceiveAuthenticationChallenge”
这里是 “didReceiveAuthenticationChallenge” 委托的代码:
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:
(NSURLAuthenticationChallenge *)challenge
{
//USE STORED CREDENTIALS
Credentials* cred = [[Credentials alloc] init];
NSString* userName = cred.userName;
NSString* pass = cred.pass;
NSString* authMethod = [[challenge protectionSpace] authenticationMethod];
//Kerberos (Negotiate) needs "[email protected]" as username
//NTLM Needs domain\\username
if ([authMethod isEqualToString:NSURLAuthenticationMethodNTLM]) {
userName = [NSString stringWithFormat:@"%@%@", @"es\\" , userName];
}
if ([authMethod isEqualToString:NSURLAuthenticationMethodNegotiate]) {
userName = [NSString stringWithFormat:@"%@%@", userName, @"@subdomain.domain.com"];
}
NSLog(@"Auth method in use: %@" , authMethod);
NSLog(@"User: %@" , userName);
NSLog(@"Pass: %@" , pass);
if ([challenge previousFailureCount] <= 1) {
NSLog(@"received authentication challenge");
NSURLCredential *credential;
credential = [NSURLCredential
credentialWithUser:userName
password:pass
persistence:NSURLCredentialPersistenceForSession];
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
}
else {
NSLog(@"Authentication error");
NSLog(@"Failed login with status code: %d", [(NSHTTPURLResponse*)[challenge failureResponse]statusCode]);
[[challenge sender] cancelAuthenticationChallenge:challenge];
}
}
'didReceiveAuthenticationChallenge'方法是否被调用? – 2012-08-16 12:55:36
是的,它叫,我可以在那里放一些断点(而代码工作形式W2003服务器) – malamirada 2012-08-16 14:06:37
“不幸”我没有看到任何与你的iOS方法不寻常的东西。任何机会调查挑战响应是否回到服务器,如果有,那里会发生什么? – 2012-08-16 14:53:01