1

UIWebview で NTLM 認証を行おうとしています。調べてこんな感じで書きました。しかし、私の NSLog には、「got auth challange」しか表示されませんが、「received response via 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;
}
4

1 に答える 1