但我的问题是,如果我输入错误的密码,我无法加载网站,它只显示一个白色的屏幕.
如果我传递了正确的用户名/密码,它将加载网站.
有没有办法处理我的身份验证用户名/密码是正确还是错误?
我正在使用此代码.
- (voID)connection:(NSURLConnection *)connection dIDReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodNTLM]){ NSURLCredential *credentail = [NSURLCredential credentialWithUser:@"username" password:@"Password" persistence:NSURLCredentialPersistenceForSession]; [[challenge sender] useCredential:credentail forAuthenticationChallenge:challenge];}}
上面的代码中包含正确的用户名和密码.如果我将用户名更改为“用户”或密码为“通过”,我无法加载该网站.如何捕获身份验证错误?
谢谢.
解决方法 我刚发现它.只需要再添加1个验证. [[challenge prevIoUsFailureCount] == 0.这里是代码.- (voID)connection:(NSURLConnection *)connection dIDReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {//receive a authenticate and challenge with the user credentialif ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodNTLM] && [challenge prevIoUsFailureCount] == 0){ NSURLCredential *credentail = [NSURLCredential credentialWithUser:@"username" password:@"password" persistence:NSURLCredentialPersistenceForSession]; [[challenge sender] useCredential:credentail forAuthenticationChallenge:challenge];}else { UIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"Error Message" message:@"InvalID credentails" delegate:self cancelbuttonTitle:@"OK" otherbuttonTitles:nil]; [alert show]; [alert release];}}
谢谢. 总结
以上是内存溢出为你收集整理的ios – UIWebview didReceiveAuthenticationChallenge全部内容,希望文章能够帮你解决ios – UIWebview didReceiveAuthenticationChallenge所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)