该服务器的证书无效

我知道,如果我使用以下nsurlconnectiondelegate它将被修复

– 连接:willSendRequestForAuthenticationChallenge: – 连接:canAuthenticateAgainstProtectionSpace

但我正在尝试使用

sendAsynchronousRequest:队列:completionHandler:

所以你没有得到callback。 我看着它跟随的苹果文档

如果需要进行身份validation才能下载请求,则必须将所需凭据指定为URL的一部分。 如果身份validation失败,或者凭据丢失,则连接将尝试继续而没有凭据。

我无法弄清楚如何做到这一点。 当我抬起头时,我所得到的就是这个私人电话

+(void)setAllowsAnyHTTPSCertificate:(BOOL)inAllow forHost:(NSString *)inHost;

任何想法如何做到这一点?

以下是我得到的错误

该服务器的证书无效。 您可能正在连接到假装为“example.com = 0x8b34da0 {NSErrorFailingURLStringKey = https://example.com/test/,NSLocalizedRecoverySuggestion =您要连接到服务器?NSErrorFailingURLKey = https:/ /example.com/test/,NSLocalizedDescription =此服务器的证书无效。 你可能会连接到一个伪装成“example.com”的服务器,这个服务器可能会把你的机密信息置于危险之中,NSUnderlyingError = 0xa26c1c0“这个服务器的证书是无效的,你可能连接到假装成为“example.com”这可能会把你的机密信息置于危险之中。“,NSURLErrorFailingURLPeerTrustErrorKey =

你不能用你正在尝试的方式修复它

  • 要么下降到CFNetworking允许不好的证书
  • 使用NSConnection与一个委托和一个undoc'd方法
  • 使用你find的私人API

一切都不好。 CFNetwork现在必须是苹果,但其他两种方法甚至不是appstore安全的

更好地修复服务器。 这是最简单和最干净的

您正在使用的networking服务器是要求服务器信任身份validation,您需要适当的响应与适当的行动。 您需要实现connection:willSendRequestForAuthenticationChallenge:委托方法并使用SecTrustRef来validation它。

更多信息可以在这里find: – https://developer.apple.com/library/ios/technotes/tn2232/_index.html

这是我的代码来解决错误:

 - (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { NSURLProtectionSpace *protectionSpace = [challenge protectionSpace]; id<NSURLAuthenticationChallengeSender> sender = [challenge sender]; if ([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust]) { SecTrustRef trust = [[challenge protectionSpace] serverTrust]; NSURLCredential *credential = [[NSURLCredential alloc] initWithTrust:trust]; [sender useCredential:credential forAuthenticationChallenge:challenge]; } else { [sender performDefaultHandlingForAuthenticationChallenge:challenge]; } } 

如果你正在使用AFNetworking ,你可以使用这个代码:

(就像一个临时的客户端解决scheme!)

 AFHTTPSessionManager * apiManager = [AFHTTPSessionManager initWithBaseURL:[NSURL URLWithString:baseURL]; AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; policy.allowInvalidCertificates = YES; apiManager.securityPolicy = policy; 

这个问题不能用你尝试块的方式解决。 您需要设置委托并实施身份validation质询委托来绕过证书validation。 最好的解决办法是创build一个正确的证书(确保它不是自签名的),或者把协议改成HTTP,如果你没有问题的话。

这是一个证书错误。 您需要更改您的设置,以便您的程序/操作系统忽略证书,或将URL /证书添加到可信列表。

对不起,是authentication,证书是authentication。 我看了一下,发现了这篇文章。

不知道是否能解决你的问题,但基本上说,他们不包括连接到一个网站的情况下如何在文档中的证书。

http://www.cocoanetics.com/2009/11/ignoring-certificate-errors-on-nsurlrequest/

在我的情况下,这个错误发生是由于我的防火墙阻止了所需的url。 删除防火墙限制后,它工作正常