我有一个3 baseURL
这三个有不同的ssl证书,我已下载一个证书和硬编码在Xcode项目,即使我更改url
请求应用程序不阻止请求。
我正在上课
class APIManager {
static let sharedInstance = APIManager()
private var manager : SessionManager?
func sessionManager() -> SessionManager {
if let manage = self.manager {
return manage
}
else {
let serverTrustpolicies: [ String: ServerTrustPolicy] = ["url" : .pinPublicKeys(publicKeys: ServerTrustPolicy.publicKeys(), validateCertificateChain: true, validateHost: true)
]
self.manager = SessionManager(
serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustpolicies)
)
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 30
self.manager = SessionManager(configuration: configuration)
return self.manager!
}
}
}
APIManager.sharedInstance.sessionManager().upload(multipartFormData: { (multipartFormData)
}
谁能解释实施?
您必须为要验证的每个主机显式设置ServerTrustPolicy
值。因此,在创建策略字典时,需要传递每个主机。
let serverTrustPolicies: [String: ServerTrustPolicy] = ["url" : .pinPublicKeys(publicKeys: ServerTrustPolicy.publicKeys(), validateCertificateChain: true, validateHost: true)]
这应该添加您的其他基本URL,并使用适当的策略集。