我有一个UIWebView
去一个有登录按钮的网站。一旦按下登录按钮(例如在Safari中),它会提示登录,然后调用通过AD进行身份验证并登录用户的Web服务。我试图在我的UIWebView
中工作,但是didReceiveAuthenticationChallenge
永远不会被召唤。有任何想法吗?didReceiveAuthenticationChallenge不被称为
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
NSLog(@"Authed = %d", _authed);
NSLog(@"Did start loading: %@ auth:%d", [[request URL] absoluteString], _authed);
NSString *theURL = [[request URL] absoluteString];
currentURL = [[request URL] absoluteString];
if (!_authed) {
_authed = NO;
[[NSURLConnection alloc] initWithRequest:request delegate:self];
NSLog(@"shouldStartLoadWithRequest Return NO");
return NO;
}
NSLog(@"shouldStartLoadWithRequest Return YES");
return YES;
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
{
NSLog(@"got auth challange");
NSLog(@"previousFailureCount = %d", [challenge previousFailureCount]);
ch = challenge;
[[challenge sender] useCredential:[NSURLCredential credentialWithUser:@"myusername" password:@"mypassword" persistence:NSURLCredentialPersistencePermanent] forAuthenticationChallenge:challenge];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
{
NSLog(@"received response via nsurlconnection");
_authed = YES;
NSString *urladdress = currentURL;
NSURL *url = [NSURL URLWithString:urladdress];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[itemWebView loadRequest:urlRequest];
}
- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection;
{
return NO;
}
有没有办法可以手动调用didReceiveAuthenticationChallenge
方法?
该方法用于提供凭据以响应来自服务器的HTTP Auth质询,而不是执行更典型的基于表单的身份验证。你确定该网站使用HTTP身份验证? –
嗨,约翰,是的,它不是基于表单的身份验证。当在页面上按下登录按钮(在Safari中)时,用户会被提示一个ntfs登录屏幕,该屏幕应该触发该方法,但由于某种原因,屏幕没有。 – DavidB