private struct TestCertificates {
static let rootCA = TestCertificates.certificate( )
static func certificate() -> SecCertificate {
var filePath = Bundle.main.path(forResource: "certificate", ofType: "der")!
let data = try! Data(contentsOf: URL(fileURLWithPath: filePath))
let certificate = SecCertificateCreateWithData(nil, data as CFData)!
return certificate
}
}
private let dateSManager: Session = {
let certificates: [SecCertificate] = [TestCertificates.rootCA]
let trustPolicy = PinnedCertificatesTrustEvaluator(certificates: certificates , performDefaultValidation: false, validateHost: false)
var baseUrl = "www.testurl.com"
let manager = ServerTrustManager(evaluators: [baseUrl: trustPolicy])
let configuration = URLSessionConfiguration.af.default
return Session(configuration: configuration, serverTrustManager: manager)
}()
调用的时候 直接用就行
dateSManager.request(request ).responseJSON { (responseData) in
}
网友评论