[iOS10 2017.1.1 Https适配] 使用AFNetWorking3.0 https适配

参考链接

iOS 9 HTTPS适配 
http://www.jianshu.com/p/b03ae4a1a2d3

IOS Https适配摸索
http://www.jianshu.com/p/f312a84a944c


 关于https的简介和说明我都是参考下面的文章:(谢谢文章作者)

1.http://my.oschina.net/vimfung/blog/494687

2.http://oncenote.com/2014/10/21/Security-1-HTTPS/ 

3.http://blog.csdn.net/dachao_me/article/details/48624685?ref=myread

马上就要2017年1月1号, 不知苹果会如何限制http类的接口,所以适配https还是早作打算

上面的链接基本看一遍 ,应该就能做好适配,而且如果只是简单的对部分接口做https 那应该不会太难

1.首先你要问后台拿到证书(jks格式/Mac:.cer格式) ,或者你可以打开请求的完整链接 在Mac上下载该证书 (导入Xcode工程)

这里写图片描述

2.删除之前为了跳过https而在plist.info里面的key

这里写图片描述

3.在AFNetWorking3.0 中 添加获取证书

-(void)getHttpsImageInfo{
    NSString *striCer = [[NSBundle mainBundle] pathForResource:@"StartCom Certification Authority" ofType:@"cer"];
    NSData *data = [NSData dataWithContentsOfFile:striCer];
    NSSet *set = [NSSet setWithObject:data];

    AFSecurityPolicy *securityPplicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    securityPplicy.allowInvalidCertificates = YES;
    securityPplicy.validatesDomainName = YES;
    [securityPplicy setPinnedCertificates:set];

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"image/png", nil];
    [manager GET:@"https://www.jiefengpay.com:8443/app/andorid/1.png" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        NSLog(@"********************* %@",downloadProgress);
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"%@%@",responseObject,[responseObject class]);
        NSData *data = responseObject;
        UIImage *image = [UIImage imageWithData:data];
        UIImageView *vi = [[UIImageView alloc] initWithImage:image];
        vi.frame = [UIScreen mainScreen].bounds;
        [[UIApplication sharedApplication].keyWindow addSubview:vi];
        NSLog(@"++++++++++++++++++++++++++++++++++");
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);

    }];

}

做过Https适配后的请求结果

这里写图片描述

同时,后台没有做https的请求结果error

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值