(void)connection:(NSURLConnection *)connectiondidReceiveAuthentication Challenge:(NSURLAuthenticationChall enge*)challenge
{
NSString* username =@"Private";
NSString* password =@"aaa";
NSURLCredential * cre =[[NSURLCredential alloc] initWithUser:usernamepassword:password
persistence:NSURLCredentialPersisten ceNone];
[[challenge sender]useCredential:creforAuthenticationChallen ge:challenge];
}
如果用户名或密码输入错误如下:
想判断是否失败就
if ([challengefailureResponse])
{
NSLog(@"fail");
}
{
NSString* username =@"Private";
NSString* password =@"aaa";
NSURLCredential * cre =[[NSURLCredential alloc] initWithUser:usernamepassword:password
[[challenge sender]useCredential:creforAuthenticationChallen
}
如果用户名或密码输入错误如下:
想判断是否失败就
if ([challengefailureResponse])
{
}
本文介绍了一个NSURLConnection中处理身份验证挑战的方法实现,并演示了如何使用NSURLCredential来响应这些挑战。同时,文中还提供了检查认证失败的基本逻辑。
363

被折叠的 条评论
为什么被折叠?



