我一直在使用以下代码
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
operation.allowsInvalidSSLCertificate=YES;
现在我已将 AFNetworking 更改为最新版本 2.0。操作.allowsInvalidSSLCertificate不再与AFHTTP请求操作。根据我使用的文件
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.securityPolicy.allowInvalidCertificates = YES;
我的请求代码是
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog (@"success: %@", operation.responseString);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", error.description);
}
];
[operation start];
[operation waitUntilFinished];
但这不适用于需要证书的 HTTPS。我应该做什么才能使这项工作有效?
我通过之前添加以下代码解决了这个问题[操作开始];
AFSecurityPolicy *sec=[[AFSecurityPolicy alloc] init];
[sec setAllowInvalidCertificates:YES];
operation.securityPolicy=sec;
发生这种情况是因为AFHTTP请求操作管理器未连接到AFHTTP请求操作。所以设置管理器的安全证书不能在请求操作中发挥作用。所以必须初始化并分配一个给AFHTTP请求操作.
希望这对某人有帮助:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)