2012-07-27 95 views
0
 - (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*)@"[email protected]" 
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; 
     //} 

我用这个方法来从代理网络访问公开网址,但其委托didReceiveAuthenticationChallenge是没有得到所谓的委托方法didReceiveAuthenticationChallenge是没有得到所谓的

回答

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

     return YES; 
    } 

然后它会调用!

相关问题