<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
if(challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) {
// 告诉服务器,客户端信任证书
// 创建凭据对象
NSURLCredential *credntial = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
// 告诉服务器信任证书
[challenge.sender useCredential:credntial forAuthenticationChallenge:challenge];
}
}
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * __nullable credential))completionHandler {
// 判断是否是信任服务器证书
if(challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) {
// 告诉服务器,客户端信任证书
// 创建凭据对象
NSURLCredential *credntial = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
// 通过completionHandler告诉服务器信任证书
completionHandler(NSURLSessionAuthChallengeUseCredential,credntial);
}
NSLog(@"protectionSpace = %@",challenge.protectionSpace);
}
// 1.初始化单例类 AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager]; mgr.securityPolicy.SSLPinningMode = AFSSLPinningModeCertificate; // 2.设置证书模式 NSString * cerPath = [[NSBundle mainBundle] pathForResource:@"xxx" ofType:@"cer"]; NSData * cerData = [NSData dataWithContentsOfFile:cerPath]; mgr.securityPolicy.pinnedCertificates = [[NSArray alloc] initWithObjects:cerData, nil]; // 客户端是否信任非法证书 mgr.securityPolicy.allowInvalidCertificates = YES; // 是否在证书域字段中验证域名 [mgr.securityPolicy setValidatesDomainName:NO];
// 1.初始化单例类 AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager]; mgr.securityPolicy.SSLPinningMode = AFSSLPinningModeCertificate; // 2.设置非校验证书模式 mgr.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; mgr.securityPolicy.allowInvalidCertificates = YES; [mgr.securityPolicy setValidatesDomainName:NO];
// 1.初始化 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.securityPolicy.SSLPinningMode = AFSSLPinningModeCertificate; // 2.设置证书模式 NSString * cerPath = [[NSBundle mainBundle] pathForResource:@"xxx" ofType:@"cer"]; NSData * cerData = [NSData dataWithContentsOfFile:cerPath]; manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate withPinnedCertificates:[[NSSet alloc] initWithObjects:cerData, nil]]; // 客户端是否信任非法证书 mgr.securityPolicy.allowInvalidCertificates = YES; // 是否在证书域字段中验证域名 [mgr.securityPolicy setValidatesDomainName:NO];
// 1.初始化 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; // 2.设置非校验证书模式 manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; manager.securityPolicy.allowInvalidCertificates = YES; [manager.securityPolicy setValidatesDomainName:NO];
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有