AFNetworking 3期

时间:2016-11-16 05:19:06

标签: ios ssl afnetworking afnetworking-3

AFNetworking 3中,对于无效的SSL证书,我使用了 validatesCertificateChain = false ,但现在看来该字段已被删除,我无法向我的服务器发出请求。

以下是请求类:

import UIKit
import AFNetworking

class ClientHTML: AFHTTPSessionManager {
    private static var __once: () = { () -> Void in

        let securityPolicy = AFSecurityPolicy(pinningMode: AFSSLPinningMode.certificate)
        securityPolicy.validatesDomainName = false
        securityPolicy.allowInvalidCertificates = true
        sharedInstanceTemp.securityPolicy = securityPolicy


        sharedInstanceTemp.requestSerializer = AFHTTPRequestSerializer()
        sharedInstanceTemp.responseSerializer = AFHTTPResponseSerializer()


    }()

    fileprivate static let sharedInstanceTemp = ClientHTML(baseURL: URL(string: kServer_urlBilderlings))

    static var sharedInstance:ClientHTML {
        get {
            _ = ClientHTML.__once

            return sharedInstanceTemp
        }
    }
}

我的请求是:

ClientHTML.sharedInstance.post("https://acs-web-test.firstdata.lv", parameters: nil, progress: { (progress) in
            print("progress = ", progress)
        }, success: { (task, response) in
            let data = response as! Data
            let html = String(data: data, encoding: .utf8)
            print("success responce = ", html)
        }, failure: { (task, error) in
            print("error = ", error)
        })

根据this post,我必须使用validatesCertificateChain属性。有人可以帮忙吗?

3 个答案:

答案 0 :(得分:2)

我通过将let securityPolicy = AFSecurityPolicy(pinningMode: AFSSLPinningMode.certificate)更改为let securityPolicy = AFSecurityPolicy(pinningMode: AFSSLPinningMode.none)

来解决了这个问题

答案 1 :(得分:2)

对于没有SSL固定的objective-c用户setAllowInvalidCertificates:YES

AFSecurityPolicy *sec = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
[sec setAllowInvalidCertificates:YES];
[sec setValidatesDomainName:NO];
manager.securityPolicy = sec;

答案 2 :(得分:0)

Objective-C

lo