NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"证书名称" ofType:@"cer"]; NSData *cerData = [NSData dataWithContentsOfFile:cerPath]; NSSet *cerSet = [[NSSet alloc]initWithObjects:cerData, nil]; AFSecurityPolicy *securityPoliy = [AFSecurityPolicy defaultPolicy]; //allowInvalidCertificates 是否允许无效证书(也就是自建的证书),默认为NO //如果是需要验证自建证书,需要设置为YES securityPoliy.allowInvalidCertificates = YES; //validatesDomainName 是否需要验证域名,默认为YES; securityPoliy.validatesDomainName = NO; //设置证书 [securityPoliy setPinnedCertificates:cerSet]; [dxClient setSecurityPolicy:securityPoliy];
//如果使用自建证书,需要设置为YES
securityPoliy.allowInvalidCertificates = YES;