[英]NTLM Authentication Xcode
I am trying to do NTLM authentication with UIWebview. 我正在尝试使用UIWebview进行NTLM身份验证。 I have researched and I wrote like this.
我已经研究过,并且这样写。 But in my NSLog, I only see
"got auth challange" but I don't see
"received response via nsurlconnection" .
但是在我的NSLog中,我仅看到“获得身份验证挑战”,但没有看到
“通过nsurlconnection收到的响应” 。 Please help me.
请帮我。 I am stuck with this for more than 5 days.
我坚持了超过5天。 I am testing with
ios 6.1 .
我正在使用ios 6.1进行测试。 I appreciate any help :)
感谢您的帮助:)
-(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;
}
It worked for me by using this instead for your didReceiveAuthenticationChallange: 通过为您的didReceiveAuthenticationChallange使用此方法,它对我有用:
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge
{
NSLog(@"got auth challange");
if ([challenge previousFailureCount] ==0)
{
[[challenge sender] useCredential:[NSURLCredential credentialWithUser:@"username" password:@"password" persistence:NSURLCredentialPersistenceForSession] forAuthenticationChallenge:challenge];
}
else
{
NSLog(@"Did cancelAuthenticationChallenge");
[[challenge sender] cancelAuthenticationChallenge:challenge];
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.