美文网首页
https自签名证书在客户端本地设置

https自签名证书在客户端本地设置

作者: 雷霆嘎巴嘎嘎 | 来源:发表于2018-03-06 15:11 被阅读19次
    - (AFHTTPSessionManager *)sessionManager
    {
    if (_sessionManager == nil) {
    
        NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"server_https" ofType:@"cer"];
        NSData * certData =[NSData dataWithContentsOfFile:cerPath];
        NSSet * certSet = [[NSSet alloc] initWithObjects:certData, nil];
        AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
        // 是否允许,NO-- 不允许无效的证书
        [securityPolicy setAllowInvalidCertificates:YES];
          // 设置证书
          [securityPolicy setPinnedCertificates:certSet];
          [securityPolicy setValidatesDomainName:NO];
        
        _sessionManager = [AFHTTPSessionManager manager];
        _sessionManager.securityPolicy = securityPolicy;
        _sessionManager.responseSerializer =        [AFHTTPResponseSerializer serializer];
      }
      return _sessionManager;
      }
    

    相关文章

      网友评论

          本文标题:https自签名证书在客户端本地设置

          本文链接:https://www.haomeiwen.com/subject/sotrfftx.html