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

- (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自签名证书在客户端本地设置)