自己做的https证书 在iOS上请求https 报错 怎么能越过SSL证书验证
黄舟
黄舟 2017-04-17 17:09:21
0
5
711

报错为 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>
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(5)
洪涛

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.

PHPzhong

Try upgrading to xcode7.1, there is an option YES. . . .

Ty80

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>
左手右手慢动作

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协议的请求
小葫芦

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template