wobuyayi

Error Domain=NSURLErrorDomain Code=-1202,Https服务器证书无效

2017-01-10 16:01  Hi,David  阅读(6637)  评论(0编辑  收藏  举报

错误:“此服务器的证书无效。您可能正在连接到一个伪装成“www.xxxxxx.com”的服务器, 这会威胁到您的机密信息的安全

原因:安全证书是自建证书,没有得到认证。

解决方法:

1.导入NSURLSessionDelegate

2.访问网络时创建NSURLSession对象时,采用NSURLSession *session=[NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[[NSOperationQueue alloc] init]];

3.在认证的代理方法中强制信任证书

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler{
    NSURLCredential *card = [[NSURLCredential alloc] initWithTrust:challenge.protectionSpace.serverTrust];
    completionHandler(NSURLSessionAuthChallengeUseCredential,card);
}

 

参考链接:http://www.qingpingshan.com/rjbc/ios/181533.html

分类:

技术点:

相关文章:

  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2021-12-03
  • 2021-09-21
  • 2021-11-05
猜你喜欢
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案