AFNetworking允许不通过证书验证访问https(AFNetworking+SSL)

一 AFNetworking如何允许不通过证书验证访问https?

查了多种资料,试过很多方法,最终在stackoverflow中找到方法。


1 使用AFHTTPRequestOperation 和 AFHTTPRequestOperationManager 分别加上

- (void)setOpration:(AFHTTPRequestOperation *)opration
{
    opration.securityPolicy.allowInvalidCertificates = YES;
    
}

- (void)managerSetOpration:(AFHTTPRequestOperationManager *)opration
{
    opration.securityPolicy.allowInvalidCertificates = YES;
}


2 修改AFNetworking中修改源码,在AFSecurityPolicy.m注释掉这几句

- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust
                  forDomain:(NSString *)domain
{
//    if (domain && self.allowInvalidCertificates && self.validatesDomainName && (self.SSLPinningMode == GMAFSSLPinningModeNone || [self.pinnedCertificates count] == 0)) {
//        // https://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/NetworkingTopics/Articles/OverridingSSLChainValidationCorrectly.html
//        //  According to the docs, you should only trust your provided certs for evaluation.
//        //  Pinned certificates are added to the trust. Without pinned certificates,
//        //  there is nothing to evaluate against.
//        //
//        //  From Apple Docs:
//        //          "Do not implicitly trust self-signed certificates as anchors (kSecTrustOptionImplicitAnchors).
//        //           Instead, add your own (self-signed) CA certificate to the list of trusted anchors."
//        NSLog(@"In order to validate a domain name for self signed certificates, you MUST use pinning.");
//        return NO;
//    }


如果要使用自签名证书进行验证,请参照 

iOS实用技巧 - AFNetworking2安全的使用自签证书访问HTTPS


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值