问题
in alamofire 4 I used this code to disable sever evaluation:
private var Manager : Alamofire.Session = {
// Create the server trust policies
let serverTrustPolicies: [String: ServerTrustPolicy] = ["serverurl.com": .disableEvaluation]
// Create custom manager
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = Alamofire.Session.defaultHTTPHeaders
let man = Alamofire.Session(
configuration: URLSessionConfiguration.default,
serverTrustPolicyManager: ServerTrustManager(policies: serverTrustPolicies)
)
return man
}()
but is not working anymore in alamofire 5 with swift 5 xcode 10.2, I got this errors.
Use of undeclared type 'ServerTrustPolicy' Type 'Session' has no member 'defaultHTTPHeaders'
but I cant find a new way to make this work with alamofire 5.
回答1:
ServerTrustPolicy
has been replaced with the protocol ServerTrustEvaluating
in Alamofire 5, and DisabledEvaluator
has replaced the .disabled
enum case. To replicate the custom setup you had before:
private let session: Session = {
let manager = ServerTrustManager(evaluators: ["serverurl.com": DisabledEvaluator()])
let configuration = URLSessionConfiguration.af.default
return Session(configuration: configuration, serverTrustManager: manager)
}()
来源:https://stackoverflow.com/questions/55543462/how-to-use-alamofires-servertrustpolicy-disableevaluation-in-swift-5-alamofire-5