【发布时间】:2012-05-30 03:19:55
【问题描述】:
我正在使用以下代码对远程服务器的用户进行身份验证。如果我提供了正确的用户名和密码,则没有问题,因为正在进行身份验证并且我正在从服务器获得响应。
但是当我提供错误的凭据时,此方法会以递归方式调用,因此我无法破解它。
请帮助我,如何解决这个问题,以便我能够显示身份验证失败警报消息。
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
NSURLCredential *credential = [NSURLCredential credentialWithUser:@"username"
password:@"password"
persistence:NSURLCredentialPersistenceForSession];
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
}
【问题讨论】:
标签: objective-c ios ios5 basic-authentication