我通常对编程还是陌生的,所以我很难理解这个概念,因此请体谅, 我创建了一个经理实例
import Alamofire
class SSLManager: SessionManager {
static let instance = SSLManager()
var manager: SessionManager?
func sslPinning() {
let hostname = "My Host Link"
let cert = "_stackexchangecom"
let pathToCert = Bundle.main.path(forResource: cert, ofType: "der")
let localCertificate = NSData(contentsOfFile: pathToCert!)
let certificates = [SecCertificateCreateWithData(nil, localCertificate!)!]
let serverTrustPolicy = ServerTrustPolicy.pinCertificates(
certificates: certificates,
validateCertificateChain: true,
validateHost: true
)
let serverTrustPolicies = [hostname: serverTrustPolicy,"insecure.expired-apis.com": .disableEvaluation]
let serverTrustPolicyManager = ServerTrustPolicyManager(policies: serverTrustPolicies)
let sessionConfiguration = URLSessionConfiguration.default
let afManager = SessionManager(
configuration: sessionConfiguration,
serverTrustPolicyManager: serverTrustPolicyManager
)
self.manager = afManager
}
}
但是即使使用stackoverflow证书,我的get请求也始终返回数据