问题
I need help with trying to bypass/ignor a self signing certificate.. I have looked everywhere and cannot find anything that has worked for me thus far..
I am trying to implements this here however im not sure how to use this code
@implementation NSURLRequest(AllowAllCerts)
+ (BOOL) allowsAnyHTTPSCertificateForHost:(NSString *) host {
return YES;
}
@end
I add it to my app delegate but then I dont know what to do with it?
any help would be greatly appreciated..
currently I am not using anything because nothing has worked for me..
回答1:
This is how I got it to work. I added these two methods just below the method where I call my connection to start.
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
来源:https://stackoverflow.com/questions/9458989/how-to-ignore-self-signing-certificate-with-nsurlrequest