AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];// allowInvalidCertificates 是否允许无效证书(也就是自建的证书),默认为NO// 如果是需要验证自建证书,需要设置为YESsecurityPolicy.allowInvalidCertificates =YES; [securityPolicy setValidatesDomainName:NO]; [manger setSecurityPolicy:securityPolicy];
Swift用Alamofire解决方案
public func defaultAlamofireManager() -> Manager {letconfiguration = URLSessionConfiguration.default configuration.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeadersletpolicies: [String: ServerTrustPolicy] = ["api.domian.cn": .disableEvaluation ]letmanager = Alamofire.SessionManager(configuration: configuration,serverTrustPolicyManager: ServerTrustPolicyManager(policies: policies)) manager.startRequestsImmediately =falsereturnmanager}
网友评论