作家
登录

iOS AFNetworking框架HTTPS请求配置

作者: 来源: 2017-04-23 16:50:37 阅读 我要评论

  • [manager setSessionDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition(NSURLSession*session, NSURLAuthenticationChallenge *challenge, NSURLCredential *__autoreleasing*_credential) { 
  •     NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling; 
  •     __autoreleasing NSURLCredential *credential =nil; 
  •     if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { 
  •         if([manager.securityPolicy evaluateServerTrust:challenge.protectionSpace.serverTrust forDomain:challenge.protectionSpace.host]) { 
  •             credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; 
  •             if(credential) { 
  •                 disposition =NSURLSessionAuthChallengeUseCredential; 
  •             } else { 
  •                 disposition =NSURLSessionAuthChallengePerformDefaultHandling; 
  •             } 
  •         } else { 
  •             disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge; 
  •         } 
  •     } else { 
  •         // client authentication 
  •         SecIdentityRef identity = NULL
  •         SecTrustRef trust = NULL
  •         NSString *p12 = [[NSBundle mainBundle] pathForResource:@"client"ofType:@"pfx"]; 
  •         NSFileManager *fileManager =[NSFileManager defaultManager]; 
  •  
  •         if(![fileManager fileExistsAtPath:p12]) 
  •         { 
  •             NSLog(@"client.p12:not exist"); 
  •         } 
  •         else 
  •         { 
  •             NSData *PKCS12Data = [NSData dataWithContentsOfFile:p12]; 
  •             #加载PKCS12证书,pfx或p12 
  •             if ([MyAFNetworking extractIdentity:&identity andTrust:&trust fromPKCS12Data:PKCS12Data]) 
  •             { 
  •                 SecCertificateRef certificate = NULL

      推荐阅读

      人工智能时代,技术人员应该掌握的5项技能

    3.平台及数据治理才能 在2016年,人工智能公司产生的资金收入估值达到了80亿美元,并且这一数字有望在将来的三年内翻五倍。企业家们都纷纷投资人工智能,不仅将其作为一种降低成本的方法,>>>详细阅读


    本文标题:iOS AFNetworking框架HTTPS请求配置

    地址:http://www.17bianji.com/lsqh/34908.html

  • 关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)