报错为 NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9824)
还有这个错误 CFNetwork SSLHandshake failed (-9824)
代码如下
NSURL *url = [NSURL URLWithString:@"https://booking.cn.fcm.travel/img/200049324/144799957714318319/20151120140610983315.png"];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
UIImageView *image1 = [[UIImageView alloc] init];
image1.frame= CGRectMake(10, 10, 100, 100);
image1.image=image;
[self.view addSubview:image1];
下面的操作是不管用的
info.plist加上这一段,右键 info.plist -> open as -> source code
用代码加
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
PHP中文网2017-04-17 17:11:21
Buy an SSL certificate. Customized ones will not pass. Please refer to the evil 12306.
Currently WoSign’s free SSL cannot pass Android and IOS certification.
Use a paid one, just use the cheapest RapidSSL. Dozens of dollars a year.
PHP中文网2017-04-17 17:11:21
AppDelegate.m
@implementation NSURLRequest(DataController)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
return YES;
}
@end
If it is XCODE 7 or above version, plist needs to be added
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
ringa_lee2017-04-17 17:11:21
1. Self-signed certificates are not trusted. You can implement conection proxy and ignore the certificate, which is more troublesome to implement.
2. Your server should be set to only support https requests. You can set it to support two protocols at the same time
如果是自建证书,没有经过权威机构认证的证书,那么需要将NSAllowsArbitraryLoads设置为YES才能通过。NSAllowsArbitraryLoads为YES,以前的HTTP请求也能通过。->现在是没有http协议的请求
高洛峰2017-04-17 17:11:21
You can replace the self-signed SSL certificate with a free SSL certificate trusted by browsers, such as startssl, WoSign free SSL, let us encrypt