how to ignore self-signing certificate with NSURLRequest

爱⌒轻易说出口 提交于 2019-12-08 07:44:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!