Я пытаюсь выполнить аутентификацию NTLM с помощью UIWebview. Я исследовал, и я написал, как это. Но в моем NSLog я вижу только "получил запрос на аутентификацию", но не вижу "получен ответ через nsurlconnection" . Пожалуйста помогите. Я застрял с этим в течение более 5 дней. Я тестирую ios 6.1. Я ценю любую помощь :)
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
if([request.URL.host isEqualToString:@"42.61.46.2"])
{
NSURLConnection* connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
NSLog(@"%@",request);
return NO;
}
self.lbl_error.hidden = YES; //hide error message label
return YES;
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
NSLog(@"got auth challange");
if ([challenge previousFailureCount] == 0)
{
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
initWithHost: @"42.61.46.2"
port: 80
protocol: @"http"
realm: nil authenticationMethod : NSURLAuthenticationMethodNTLM];
[[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential: [NSURLCredential credentialWithUser:@"example" password:@"example" persistence:NSURLCredentialPersistenceForSession] forProtectionSpace:protectionSpace];
}
else
{
[[challenge sender] cancelAuthenticationChallenge:challenge];
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"received response via nsurlconnection");
NSURL* url = [NSURL URLWithString:@"http://42.61.46.2"]; //create a NSURL object
if(activeWebView == nil)
{
//If there is no activeWebview i.e. no webview in the collection, create a new one and show it
[self addWebViewWithURL:url];
}
else
{
NSString *url = @"http://42.61.46.2";
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[activeWebView loadRequest:urlRequest];
}
}
- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection
{
return NO;
}