美文网首页iOS倒计时
Alamofire升级5.0之后 证书验证方法更改

Alamofire升级5.0之后 证书验证方法更改

作者: 铁汁红豆 | 来源:发表于2020-03-19 11:54 被阅读0次

     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

            }            

    相关文章

      网友评论

        本文标题:Alamofire升级5.0之后 证书验证方法更改

        本文链接:https://www.haomeiwen.com/subject/kgukyhtx.html