【发布时间】:2013-03-27 09:09:35
【问题描述】:
我可以使用 NSURL 进行身份验证,用户可以分配用户名和密码。但是,我遇到了另一个问题。如果我打开这个 http://html5test.com/ ,它也会弹出并询问用户名和密码。即使不应该获得,我也获得了身份验证。我想知道怎么做。
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if(!_auth)
{
connection_for_auto = [[NSURLConnection alloc] initWithRequest:request delegate:self];
firsttimeonly=TRUE;
[connection_for_auto start];
NSLog(@"Request >> %@ and !firsttimeonly",request);
return NO;
}
self.lbl_error.hidden = YES; //hide error message label
return YES;
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
checkTochangeUIalert=TRUE;
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Login"
message:nil
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK",@"Auto", nil];
alertView.transform=CGAffineTransformMakeScale(1.0, 0.75);
alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alertView show];
}
【问题讨论】:
标签: ios http authentication nsurlconnection