方法didReceiveAuthenticationChalle

方法didReceiveAuthenticationChalle

本文介绍了委托方法didReceiveAuthenticationChallenge没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {

            return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
        }

       - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {

        NSLog(@"got auth challange");
        NSURLCredential *newCredential;
        newCredential=[NSURLCredential credentialWithUser:    (NSString*)@"company//A1234"
password:(NSString*)@"apple@999"
persistence:NSURLCredentialPersistencePermanent];
   [[challenge  sender] useCredential:newCredential     forAuthenticationChallenge:challenge];

        NSLog(@"Auth error: %@",[[challenge  error] description]);
        NSLog(@"Failure count:%d",[challenge previousFailureCount]);
        }
        //- (id)initWithProxyHost:(NSString *)host port:(NSInteger)port type:(NSString *)type realm:(NSString *)realm  authenticationMethod:(NSString *)authenticationMethod{
        //
        //    return self;
        //}

我使用此方法从代理网络访问公共URL,但未调用其委托didReceiveAuthenticationChallenge

I use this method to access a public url from proxy network, but its delegate didReceiveAuthenticationChallenge is not getting called

推荐答案

 - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {

        return YES;
    }

然后它将调用!

这篇关于委托方法didReceiveAuthenticationChallenge没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 03:15