我在尝试绕过/忽略自签名证书时需要帮助。我到处都看过,但到目前为止找不到任何对我有用的东西。
我正在尝试实现这个 here但是我不确定如何使用此代码
@implementation NSURLRequest(AllowAllCerts)
+ (BOOL) allowsAnyHTTPSCertificateForHost:(NSString *) host {
return YES;
}
@end
我将它添加到我的应用委托(delegate)中,但我不知道如何处理它?</p>
任何帮助将不胜感激..
目前我没有使用任何东西,因为没有任何东西对我有用..
最佳答案
这就是我让它工作的方式。 我在调用连接开始的方法下方添加了这两个方法。
- (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];
}
关于iphone - 如何使用 NSURLRequest 忽略自签名证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9458989/