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